Vaguely behave like primary/replica, but the databases aren't assumed to propagate changes.
| 2 | |
| 3 | |
| 4 | class TestRouter: |
| 5 | """ |
| 6 | Vaguely behave like primary/replica, but the databases aren't assumed to |
| 7 | propagate changes. |
| 8 | """ |
| 9 | |
| 10 | def db_for_read(self, model, instance=None, **hints): |
| 11 | if instance: |
| 12 | return instance._state.db or "other" |
| 13 | return "other" |
| 14 | |
| 15 | def db_for_write(self, model, **hints): |
| 16 | return DEFAULT_DB_ALIAS |
| 17 | |
| 18 | def allow_relation(self, obj1, obj2, **hints): |
| 19 | return obj1._state.db in ("default", "other") and obj2._state.db in ( |
| 20 | "default", |
| 21 | "other", |
| 22 | ) |
| 23 | |
| 24 | def allow_migrate(self, db, app_label, **hints): |
| 25 | return True |
| 26 | |
| 27 | |
| 28 | class AuthRouter: |
no outgoing calls