1
0
mirror of https://github.com/django/django.git synced 2024-12-22 17:16:24 +00:00

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.
This commit is contained in:
Baptiste Mispelon 2014-08-03 14:02:21 +02:00
parent 72f1eb48df
commit 7432533932
2 changed files with 20 additions and 0 deletions

View File

@ -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):

View File

@ -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()