Fixed #21785: Bad handling of both auto_now and _add on deconstruct

This commit is contained in:
Andrew Godwin 2014-01-17 10:45:31 +00:00
parent dd98ccd482
commit 86e69bf3b6
2 changed files with 7 additions and 2 deletions

View File

@ -904,10 +904,9 @@ class DateField(Field):
name, path, args, kwargs = super(DateField, self).deconstruct()
if self.auto_now:
kwargs['auto_now'] = True
del kwargs['editable']
del kwargs['blank']
if self.auto_now_add:
kwargs['auto_now_add'] = True
if self.auto_now or self.auto_now_add:
del kwargs['editable']
del kwargs['blank']
return name, path, args, kwargs

View File

@ -96,6 +96,12 @@ class FieldDeconstructionTests(TestCase):
self.assertEqual(path, "django.db.models.DateTimeField")
self.assertEqual(args, [])
self.assertEqual(kwargs, {"auto_now_add": True})
# Bug #21785
field = models.DateTimeField(auto_now=True, auto_now_add=True)
name, path, args, kwargs = field.deconstruct()
self.assertEqual(path, "django.db.models.DateTimeField")
self.assertEqual(args, [])
self.assertEqual(kwargs, {"auto_now_add": True, "auto_now": True})
def test_decimal_field(self):
field = models.DecimalField(max_digits=5, decimal_places=2)