I've been trying to figure out how to automatically handle migration and queries from dynamically created databases (MySql). I have a dynamic router to which I can prefix the route to a database by name to perform a query. But then I found objects.using('db_name')
.
Does the using(...)
function remove the need for a router? Or does using(...)
supply the information evaluated in a router's following methods, specifically model._meta.app_label
:
def db_for_read(self, model, **hints):
"""
"""
if model._meta.app_label == 'db_name':
return 'db_name'
return None
def db_for_write(self, model, **hints):
"""
"""
if model._meta.app_label == 'db_name':
return 'db_name'
return None