33 lines
881 B
Python
33 lines
881 B
Python
|
|
from django.db.utils import DEFAULT_DB_ALIAS
|
|
|
|
APP_NAME = 'medicine'
|
|
DATABASE_NAME = 'medicine'
|
|
|
|
|
|
class MedicineRouter:
|
|
|
|
def db_for_read(self, model, **hints):
|
|
if model._meta.app_label in [APP_NAME]:
|
|
return DATABASE_NAME
|
|
return DEFAULT_DB_ALIAS
|
|
|
|
def db_for_write(self, model, **hints):
|
|
if model._meta.app_label in [APP_NAME]:
|
|
return DATABASE_NAME
|
|
return DEFAULT_DB_ALIAS
|
|
|
|
def allow_migrate(self, db, app_label, model_name=None, **hints):
|
|
if db == DATABASE_NAME:
|
|
return False
|
|
|
|
if app_label == APP_NAME:
|
|
return False
|
|
|
|
def allow_relation(self, obj1, obj2, **hints):
|
|
app_label_obj1 = obj1.__class__._meta.app_label
|
|
app_label_obj2 = obj2.__class__._meta.app_label
|
|
|
|
if app_label_obj1 == APP_NAME or app_label_obj2 == APP_NAME:
|
|
return True
|