# >>> in models.py >>># Add recognized model option to djangoimportdjango.db.models.optionsasoptionsoptions.DEFAULT_NAMES=options.DEFAULT_NAMES+('in_db',)# <<<# >>> in routers.py >>>classModelDatabaseRouter(object):"""Allows each model to set its own destiny"""defdb_for_read(self,model,**hints):# Specify target database with field in_db in model's Meta classifhasattr(model._meta,'in_db'):returnmodel._meta.in_dbreturnNonedefdb_for_write(self,model,**hints):# Specify target database with field in_db in model's Meta classifhasattr(model._meta,'in_db'):returnmodel._meta.in_dbreturnNonedefallow_syncdb(self,db,model):# Specify target database with field in_db in model's Meta classifhasattr(model._meta,'in_db'):ifmodel._meta.in_db==db:returnTrueelse:returnFalseelse:# Random models that don't specify a database can only go to 'default'ifdb=='default':returnTrueelse:returnFalse# <<<