Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- from django.conf import settings
- from django.db import models
- from django.contrib.auth.models import User
- class MyBeeDBRouter(object):
- '''
- - Info
- This router dispatches the SQL queries between your application and Core API.
- - Configuration
- DATABASE_ROUTERS = ['path.to.MyBeeDBRouter']
- MYBEE_DB_ROUTER_APPNAME = "MyApplication"
- MYBEE_DB_ROUTER_DATABASE = "MyCustomDB"
- '''
- def __init__(self):
- self._myappname = settings.MYBEE_DB_ROUTER_APPNAME
- self._mydbname = settings.MYBEE_DB_ROUTER_DATABASE
- def db_for_read(self, model, **hints):
- if model._app_label == self._myappname:
- return self._mydbname
- return 'default'
- def db_for_write(self, model, **hints):
- if model._meta.app_label == self._myappname:
- return self._mydbname
- return 'deafult'
- def allow_relation(self, obj1, obj2, **hints):
- if obj1._meta.app_label == self._myappname or obj2._meta.app_label == self._myappname:
- return True
- return 'default'
- def allow_syncdb(self, db, model):
- if db == self._mydbname:
- return model._meta.app_label == self._myappname
- elif model._meta.app_label == self._myappname:
- return False
- return 'deafult'
Advertisement
Add Comment
Please, Sign In to add comment