Guest User

dbrouter.py

a guest
Jul 13th, 2012
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.33 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. from django.conf import settings
  3. from django.db import models
  4. from django.contrib.auth.models import User
  5.  
  6. class   MyBeeDBRouter(object):
  7.     '''
  8.    - Info
  9.    This router dispatches the SQL queries between your application and Core API.
  10.  
  11.    - Configuration
  12.    DATABASE_ROUTERS         = ['path.to.MyBeeDBRouter']
  13.    MYBEE_DB_ROUTER_APPNAME  = "MyApplication"
  14.    MYBEE_DB_ROUTER_DATABASE = "MyCustomDB"
  15.    '''
  16.     def __init__(self):
  17.         self._myappname = settings.MYBEE_DB_ROUTER_APPNAME
  18.         self._mydbname = settings.MYBEE_DB_ROUTER_DATABASE
  19.  
  20.     def db_for_read(self, model, **hints):
  21.         if model._app_label == self._myappname:
  22.             return self._mydbname
  23.         return 'default'
  24.  
  25.     def db_for_write(self, model, **hints):
  26.         if model._meta.app_label == self._myappname:
  27.             return self._mydbname
  28.         return 'deafult'
  29.  
  30.     def allow_relation(self, obj1, obj2, **hints):
  31.         if obj1._meta.app_label == self._myappname or obj2._meta.app_label == self._myappname:
  32.             return True
  33.         return 'default'
  34.  
  35.     def allow_syncdb(self, db, model):
  36.         if db == self._mydbname:
  37.             return model._meta.app_label == self._myappname
  38.         elif model._meta.app_label == self._myappname:
  39.             return False
  40.         return 'deafult'
Advertisement
Add Comment
Please, Sign In to add comment