From 74325339327e5b8a2480aee7f482bc71f73c71f9 Mon Sep 17 00:00:00 2001 From: Baptiste Mispelon Date: Sun, 3 Aug 2014 14:02:21 +0200 Subject: [PATCH] Added missing logic to TimeField.deconstruct(). If auto_now or auto_now_add was used then the serialized field in the migration contained unnecessary `editable` and `blank` arguments. --- django/db/models/fields/__init__.py | 3 +++ tests/field_deconstruction/tests.py | 17 +++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/django/db/models/fields/__init__.py b/django/db/models/fields/__init__.py index a0f72a7fd6..0a90392e87 100644 --- a/django/db/models/fields/__init__.py +++ b/django/db/models/fields/__init__.py @@ -2083,6 +2083,9 @@ class TimeField(DateTimeCheckMixin, Field): kwargs["auto_now"] = self.auto_now if self.auto_now_add is not False: kwargs["auto_now_add"] = self.auto_now_add + if self.auto_now or self.auto_now_add: + del kwargs['blank'] + del kwargs['editable'] return name, path, args, kwargs def get_internal_type(self): diff --git a/tests/field_deconstruction/tests.py b/tests/field_deconstruction/tests.py index be73f8b19e..c5f3f63999 100644 --- a/tests/field_deconstruction/tests.py +++ b/tests/field_deconstruction/tests.py @@ -336,6 +336,23 @@ class FieldDeconstructionTests(TestCase): self.assertEqual(args, []) self.assertEqual(kwargs, {}) + def test_time_field(self): + field = models.TimeField() + name, path, args, kwargs = field.deconstruct() + self.assertEqual(path, "django.db.models.TimeField") + self.assertEqual(args, []) + self.assertEqual(kwargs, {}) + + field = models.TimeField(auto_now=True) + name, path, args, kwargs = field.deconstruct() + self.assertEqual(args, []) + self.assertEqual(kwargs, {'auto_now': True}) + + field = models.TimeField(auto_now_add=True) + name, path, args, kwargs = field.deconstruct() + self.assertEqual(args, []) + self.assertEqual(kwargs, {'auto_now_add': True}) + def test_url_field(self): field = models.URLField() name, path, args, kwargs = field.deconstruct()