-
Notifications
You must be signed in to change notification settings - Fork 0
/
routers.py
38 lines (35 loc) · 1.07 KB
/
routers.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
class HemRouter(object):
"""
A router to control all database operations on models in the
hem application.
"""
def db_for_read(self, model, **hints):
"""
Attempts to read hem models go to hem_db.
"""
if model._meta.app_label == 'hem_app':
return 'hem_db'
return None
def db_for_write(self, model, **hints):
"""
Attempts to write auth models go to hem_db.
"""
if model._meta.app_label == 'hem_app':
return 'hem_db'
return None
def allow_relation(self, obj1, obj2, **hints):
"""
Allow relations if a model in the hem app is involved.
"""
if obj1._meta.app_label == 'hem_app' or \
obj2._meta.app_label == 'hem_app':
return True
return None
def allow_migrate(self, db, app_label, model_name=None, **hints):
"""
Make sure the hem app only appears in the 'hem_db'
database.
"""
if app_label == 'hem_app':
return db == 'hem_db'
return None