-
Notifications
You must be signed in to change notification settings - Fork 0
/
routers.py
executable file
·117 lines (103 loc) · 3.38 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
class HemRouter(object):
"""
Controls database operations for 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
#Class for hwbi_db routing
class HwbiRouter(object):
"""
Controls database operations for the hwbi application.
"""
def db_for_read(self, model, **hints):
"""
Attempts to read pisces models go to hwbi_db.
"""
if model._meta.app_label == 'hwbi_app':
return 'hwbi_db'
return None
def db_for_write(self, model, **hints):
"""
Attempts to write auth models go to hwbi_db.
"""
if model._meta.app_label == 'hwbi_app':
return 'hwbi_db'
return None
def allow_relation(self, obj1, obj2, **hints):
"""
Allow relations if a model in the hwbi app is involved.
"""
if obj1._meta.app_label == 'hwbi_app' or \
obj2._meta.app_label == 'hwbi_app':
return True
return None
def allow_migrate(self, db, app_label, model_name=None, **hints):
"""
Make sure the hwbi app only appears in the 'hwbi_db'
database.
"""
if app_label == 'hwbi_app':
return db == 'hwbi_db'
return None
#Class for pisces_db routing
class PiscesRouter(object):
"""
Controls database operations for the pisces application.
"""
def db_for_read(self, model, **hints):
"""
Attempts to read pisces models go to pisces_db.
"""
if model._meta.app_label == 'pisces_app':
return 'pisces_db'
return None
def db_for_write(self, model, **hints):
"""
Attempts to write auth models go to pisces_db.
"""
if model._meta.app_label == 'pisces_app':
return 'pisces_db'
return None
def allow_relation(self, obj1, obj2, **hints):
"""
Allow relations if a model in the pisces app is involved.
"""
if obj1._meta.app_label == 'pisces_app' or \
obj2._meta.app_label == 'pisces_app':
return True
return None
def allow_migrate(self, db, app_label, model_name=None, **hints):
"""
Make sure the pisces app only appears in the 'pisces_db'
database.
"""
if app_label == 'pisces_app':
return db == 'pisces_db'
return None