| 19 | However, being aware of the cross-database problem, my routers.py looks like this: |
| 20 | {{{ |
| 21 | class AuthRouter(object): |
| 22 | auth_related = ( |
| 23 | 'auth', |
| 24 | 'admin', |
| 25 | 'contenttypes', |
| 26 | 'sessions', |
| 27 | ) |
| 28 | |
| 29 | def db_for_read(self, model, **hints): |
| 30 | if model._meta.app_label in self.auth_related: |
| 31 | return 'users' |
| 32 | return None |
| 33 | |
| 34 | def db_for_write(self, model, **hints): |
| 35 | if model._meta.app_label in self.auth_related: |
| 36 | return 'users' |
| 37 | return None |
| 38 | |
| 39 | def allow_relation(self, obj1, obj2, **hints): |
| 40 | if obj1._meta.app_label in self.auth_related or \ |
| 41 | obj2._meta.app_label in self.auth_related: |
| 42 | return True |
| 43 | return None |
| 44 | |
| 45 | def allow_migrate(self, db, app_label, model_name=None, **hints): |
| 46 | if app_label in self.auth_related: |
| 47 | return db == 'users' |
| 48 | return None |
| 49 | }}} |