Created
April 2, 2020 10:07
-
-
Save dorosch/afaf961cf2bf53b71bf78b67f3e94175 to your computer and use it in GitHub Desktop.
Django database-level router
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class StockRouter: | |
route_app_labels = {'stock'} | |
def db_for_read(self, model, **hints): | |
if model._meta.app_label in self.route_app_labels: | |
return 'nq' | |
return None | |
def db_for_write(self, model, **hints): | |
if model._meta.app_label in self.route_app_labels: | |
return 'nq' | |
return None | |
def allow_migrate(self, db, app_label, model_name=None, **hints): | |
if app_label in self.route_app_labels: | |
return True # db == 'stock' | |
return None |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment