mirror of
https://github.com/django/django.git
synced 2025-08-04 10:59:45 +00:00
Refs #33476 -- Reformatted code with Black.
This commit is contained in:
parent
f68fa8b45d
commit
9c19aff7c7
1992 changed files with 139577 additions and 96284 deletions
|
@ -9,14 +9,17 @@ class TestRouter:
|
|||
|
||||
def db_for_read(self, model, instance=None, **hints):
|
||||
if instance:
|
||||
return instance._state.db or 'other'
|
||||
return 'other'
|
||||
return instance._state.db or "other"
|
||||
return "other"
|
||||
|
||||
def db_for_write(self, model, **hints):
|
||||
return DEFAULT_DB_ALIAS
|
||||
|
||||
def allow_relation(self, obj1, obj2, **hints):
|
||||
return obj1._state.db in ('default', 'other') and obj2._state.db in ('default', 'other')
|
||||
return obj1._state.db in ("default", "other") and obj2._state.db in (
|
||||
"default",
|
||||
"other",
|
||||
)
|
||||
|
||||
def allow_migrate(self, db, app_label, **hints):
|
||||
return True
|
||||
|
@ -29,30 +32,30 @@ class AuthRouter:
|
|||
|
||||
def db_for_read(self, model, **hints):
|
||||
"Point all read operations on auth models to 'default'"
|
||||
if model._meta.app_label == 'auth':
|
||||
if model._meta.app_label == "auth":
|
||||
# We use default here to ensure we can tell the difference
|
||||
# between a read request and a write request for Auth objects
|
||||
return 'default'
|
||||
return "default"
|
||||
return None
|
||||
|
||||
def db_for_write(self, model, **hints):
|
||||
"Point all operations on auth models to 'other'"
|
||||
if model._meta.app_label == 'auth':
|
||||
return 'other'
|
||||
if model._meta.app_label == "auth":
|
||||
return "other"
|
||||
return None
|
||||
|
||||
def allow_relation(self, obj1, obj2, **hints):
|
||||
"Allow any relation if a model in Auth is involved"
|
||||
return obj1._meta.app_label == 'auth' or obj2._meta.app_label == 'auth' or None
|
||||
return obj1._meta.app_label == "auth" or obj2._meta.app_label == "auth" or None
|
||||
|
||||
def allow_migrate(self, db, app_label, **hints):
|
||||
"Make sure the auth app only appears on the 'other' db"
|
||||
if app_label == 'auth':
|
||||
return db == 'other'
|
||||
if app_label == "auth":
|
||||
return db == "other"
|
||||
return None
|
||||
|
||||
|
||||
class WriteRouter:
|
||||
# A router that only expresses an opinion on writes
|
||||
def db_for_write(self, model, **hints):
|
||||
return 'writer'
|
||||
return "writer"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue