Ticket #16088: dbutil.py

File dbutil.py, 1.6 KB (added by def@…, 13 years ago)

db router

Line 
1
2class ToolDBRouter(object):
3 """The db router for all classes in the station and catalog db's"""
4
5 def db_for_read(self, model, **hints):
6 """if app label is matcher then point to station or catalog slave db"""
7 if model.__name__.startswith('Station'):
8 return 'station'
9 if model.__name__.startswith('Catalog'):
10 return 'catalog'
11 return None
12
13 def db_for_write(self, model, **hints):
14 """if app label is matcher then point to station or catalog master db"""
15 if model.__name__.startswith('Station'):
16 return 'station'
17 if model.__name__.startswith('Catalog'):
18 return 'catalog'
19 return None
20
21 def allow_syncdb(self, db, model):
22 """Make sure the catalog and station tables only appear on catalog and station db's"""
23 value = None
24 if db == 'station':
25 if model.__name__.startswith('Station'):
26 value = True
27 elif model.__name__.startswith('Catalog'):
28 value = False
29 elif db == 'catalog':
30 if model.__name__.startswith('Catalog'):
31 value = True
32 elif model.__name__.startswith('Station'):
33 value = False
34 elif model.__name__.startswith('Catalog') or model.__name__.startswith('Station'):
35 value = False
36
37 #print 'tool: {0} / {1} / {2} / {3}'.format(db, model._meta.app_label, model.__name__, value)
38 return value
39
40 def allow_relation(self, obj1, obj2, **hints):
41 print 'allow relationship {0} to {1}'.format(obj1, obj2)
42 return None
Back to Top