Fixed #24566 -- Added support for serializing timedelta
Thanks to knbk for the report.
This commit is contained in:
parent
0f941f57ba
commit
30a3c2f74c
|
@ -351,6 +351,9 @@ class MigrationWriter(object):
|
||||||
if isinstance(value, datetime_safe.time):
|
if isinstance(value, datetime_safe.time):
|
||||||
value_repr = "datetime.%s" % value_repr
|
value_repr = "datetime.%s" % value_repr
|
||||||
return value_repr, {"import datetime"}
|
return value_repr, {"import datetime"}
|
||||||
|
# Timedeltas
|
||||||
|
elif isinstance(value, datetime.timedelta):
|
||||||
|
return repr(value), {"import datetime"}
|
||||||
# Settings references
|
# Settings references
|
||||||
elif isinstance(value, SettingsReference):
|
elif isinstance(value, SettingsReference):
|
||||||
return "settings.%s" % value.setting_name, {"from django.conf import settings"}
|
return "settings.%s" % value.setting_name, {"from django.conf import settings"}
|
||||||
|
|
|
@ -9,4 +9,5 @@ Django 1.8.1 fixes several bugs in 1.8.
|
||||||
Bugfixes
|
Bugfixes
|
||||||
========
|
========
|
||||||
|
|
||||||
* ...
|
* Added support for serializing :class:`~datetime.timedelta` objects in
|
||||||
|
migrations (:ticket:`24566`).
|
||||||
|
|
|
@ -351,6 +351,10 @@ class WriterTests(TestCase):
|
||||||
self.assertSerializedEqual(frozenset())
|
self.assertSerializedEqual(frozenset())
|
||||||
self.assertSerializedEqual(frozenset("let it go"))
|
self.assertSerializedEqual(frozenset("let it go"))
|
||||||
|
|
||||||
|
def test_serialize_timedelta(self):
|
||||||
|
self.assertSerializedEqual(datetime.timedelta())
|
||||||
|
self.assertSerializedEqual(datetime.timedelta(minutes=42))
|
||||||
|
|
||||||
def test_simple_migration(self):
|
def test_simple_migration(self):
|
||||||
"""
|
"""
|
||||||
Tests serializing a simple migration.
|
Tests serializing a simple migration.
|
||||||
|
|
Loading…
Reference in New Issue