class Router(object):
def __init__(self):
self.mapping = {'special': 'other'}
def db_for_read(self, model, **hints):
db = self.mapping.get(model._meta.app_label, 'default')
instance = hints.get('instance')
return instance._state.db or db if instance else db
def db_for_write(self, model, **hints):
return self.mapping.get(model._meta.app_label, 'default')
def allow_relation(self, obj1, obj2, **hints):
db1 = self.mapping.get(obj1._meta.app_label, 'default')
db2 = self.mapping.get(obj2._meta.app_label, 'default')
return db1 == db2
def allow_migrate(self, db, app_label, model_name=None, **hints):
return db == self.mapping.get(app_label, 'default')