Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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

  • Loading branch information...
commit 86e69bf3b67ff1e156413e07cef018ec52c2cdd4 1 parent dd98ccd
@andrewgodwin andrewgodwin authored
View
3  django/db/models/fields/__init__.py
@@ -904,10 +904,9 @@ def deconstruct(self):
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
6 tests/field_deconstruction/tests.py
@@ -96,6 +96,12 @@ def test_datetime_field(self):
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)
Please sign in to comment.
Something went wrong with that request. Please try again.