Skip to content

Commit a06efe3

Browse files
committed
implement ObjectIdAutoField.deconstruct()
Remove "auto" from path and omit default db_column from kwargs.
1 parent 460a136 commit a06efe3

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

django_mongodb/fields/auto.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@ def __init__(self, *args, **kwargs):
1515
kwargs["db_column"] = "_id"
1616
super().__init__(*args, **kwargs)
1717

18+
def deconstruct(self):
19+
name, path, args, kwargs = super().deconstruct()
20+
if self.db_column == "_id":
21+
del kwargs["db_column"]
22+
if path.startswith("django_mongodb.fields.auto"):
23+
path = path.replace("django_mongodb.fields.auto", "django_mongodb.fields")
24+
return name, path, args, kwargs
25+
1826
def get_prep_value(self, value):
1927
if value is None:
2028
return None

tests/model_fields_/test_autofield.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ class MethodTests(SimpleTestCase):
77
def test_deconstruct(self):
88
field = ObjectIdAutoField()
99
name, path, args, kwargs = field.deconstruct()
10-
self.assertEqual(path, "django_mongodb.fields.auto.ObjectIdAutoField")
10+
self.assertEqual(path, "django_mongodb.fields.ObjectIdAutoField")
1111
self.assertEqual(args, [])
12-
self.assertEqual(kwargs, {"db_column": "_id", "primary_key": True})
12+
self.assertEqual(kwargs, {"primary_key": True})
1313

1414
def test_to_python(self):
1515
f = ObjectIdAutoField()

0 commit comments

Comments
 (0)