Skip to content

Commit 5d33260

Browse files
committed
Use router from test runs
1 parent a87b14d commit 5d33260

File tree

1 file changed

+17
-13
lines changed
  • django_mongodb_cli/templates/project_template/project_name

1 file changed

+17
-13
lines changed
Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
1+
from django_mongodb_backend.utils import model_has_encrypted_fields
2+
3+
14
class EncryptedRouter:
2-
def db_for_read(self, model, **hints):
3-
if model._meta.app_label == "django_mongodb_demo":
4-
return "encrypted"
5+
def allow_migrate(self, db, app_label, model_name=None, **hints):
6+
if hints.get("model"):
7+
if model_has_encrypted_fields(hints["model"]):
8+
return db == "encrypted"
9+
else:
10+
return db == "default"
511
return None
612

7-
db_for_write = db_for_read
13+
def db_for_read(self, model, **hints):
14+
if model_has_encrypted_fields(model):
15+
return "encrypted"
16+
return "default"
817

9-
def allow_migrate(self, db, app_label, model_name=None, **hints):
10-
if app_label == "django_mongodb_demo":
11-
print("allow_migrate for django_mongodb_demo:", db)
12-
return db == "encrypted"
13-
# Don't create other app's models in the encrypted database.
14-
if db == "encrypted":
15-
return False
18+
def kms_provider(self, model):
19+
if model_has_encrypted_fields(model):
20+
return "local"
1621
return None
1722

18-
def kms_provider(self, model, **hints):
19-
return "local"
23+
db_for_write = db_for_read

0 commit comments

Comments
 (0)