Commit 3f56b842 authored by lixiaofang's avatar lixiaofang

add

parent 6f22f345
# !/usr/bin/env python
# -*- coding: utf-8 -*-
DATABASE_APPS_MAPPING = {'face': 'face', 'commodity': 'commodity'}
class DBRouter:
......@@ -15,8 +16,8 @@ class DBRouter:
# if model._meta.app_label == 'face':
# return 'face'
if model._meta.app_label == 'commodity':
return 'commodity'
if model._meta.app_label in DATABASE_APPS_MAPPING:
return DATABASE_APPS_MAPPING[model._meta.app_label]
return None
def db_for_write(self, model, **hints):
......@@ -26,29 +27,32 @@ class DBRouter:
# if model._meta.app_label == 'face':
# return 'face'
if model._meta.app_label == 'commodity':
return 'commodity'
if model._meta.app_label in DATABASE_APPS_MAPPING:
return DATABASE_APPS_MAPPING[model._meta.app_label]
return None
def allow_relation(self, obj1, obj2, **hints):
"""
Allow relations if a model in the user app is involved.
# """
# if obj1._meta.app_label == 'face' or \
# obj2._meta.app_label == 'face':
# return True
if obj1._meta.app_label == 'commodity' or \
obj2._meta.app_label == 'commodity':
return True
return None
db_obj1 = DATABASE_APPS_MAPPING.get(obj1._meta.app_label)
db_obj2 = DATABASE_APPS_MAPPING.get(obj2._meta.app_label)
if db_obj1 and db_obj2:
if db_obj1 == db_obj2:
return True
else:
return False
else:
return None
def allow_migrate(self, db, app_label, model_name=None, **hints):
"""
Make sure the auth app only appears in the 'users_db'
database.
"""
# if app_label == 'face':
# return db == 'face'
if app_label == 'commodity':
return db == 'commodity'
if db in DATABASE_APPS_MAPPING.values():
return DATABASE_APPS_MAPPING.get(app_label) == db
elif app_label in DATABASE_APPS_MAPPING:
return False
return None
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment