Skip to content

Commit b7dbd70

Browse files
committed
make create/delete_model() handle M2M tables
1 parent df2cddd commit b7dbd70

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

django_mongodb/features.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,6 @@ class DatabaseFeatures(BaseDatabaseFeatures):
126126
"schema.tests.SchemaTests.test_remove_unique_together_does_not_remove_meta_constraints",
127127
"schema.tests.SchemaTests.test_unique_together",
128128
# ManyToManyField
129-
"schema.tests.SchemaTests.test_m2m_create",
130-
"schema.tests.SchemaTests.test_m2m_create_custom",
131-
"schema.tests.SchemaTests.test_m2m_create_inherited",
132129
"schema.tests.SchemaTests.test_m2m_rename_field_in_target_model",
133130
"schema.tests.SchemaTests.test_m2m_repoint",
134131
"schema.tests.SchemaTests.test_m2m_repoint_custom",

django_mongodb/schema.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,16 @@
44
class DatabaseSchemaEditor(BaseDatabaseSchemaEditor):
55
def create_model(self, model):
66
self.connection.database.create_collection(model._meta.db_table)
7+
# Make implicit M2M tables.
8+
for field in model._meta.local_many_to_many:
9+
if field.remote_field.through._meta.auto_created:
10+
self.create_model(field.remote_field.through)
711

812
def delete_model(self, model):
13+
# Delete implicit M2m tables.
14+
for field in model._meta.local_many_to_many:
15+
if field.remote_field.through._meta.auto_created:
16+
self.delete_model(field.remote_field.through)
917
self.connection.database[model._meta.db_table].drop()
1018

1119
def add_field(self, model, field):

0 commit comments

Comments
 (0)