Fixed #21785: Bad handling of both auto_now and _add on deconstruct
This commit is contained in:
parent
dd98ccd482
commit
86e69bf3b6
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue