Skip to content

Instantly share code, notes, and snippets.

@dorosch
Created April 2, 2020 10:07
Show Gist options
  • Save dorosch/afaf961cf2bf53b71bf78b67f3e94175 to your computer and use it in GitHub Desktop.
Save dorosch/afaf961cf2bf53b71bf78b67f3e94175 to your computer and use it in GitHub Desktop.
Django database-level router
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