mirror of https://github.com/django/django.git
[1.8.x] Fixed #24566 -- Added support for serializing timedelta
Thanks to knbk for the report.
Backport of 30a3c2f74c
from master.
This commit is contained in:
parent
e7366ab1f9
commit
09188b5024
|
@ -323,6 +323,9 @@ class MigrationWriter(object):
|
|||
if isinstance(value, datetime_safe.time):
|
||||
value_repr = "datetime.%s" % value_repr
|
||||
return value_repr, {"import datetime"}
|
||||
# Timedeltas
|
||||
elif isinstance(value, datetime.timedelta):
|
||||
return repr(value), {"import datetime"}
|
||||
# Settings references
|
||||
elif isinstance(value, SettingsReference):
|
||||
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
|
||||
========
|
||||
|
||||
* ...
|
||||
* Added support for serializing :class:`~datetime.timedelta` objects in
|
||||
migrations (:ticket:`24566`).
|
||||
|
|
|
@ -339,6 +339,11 @@ class WriterTests(TestCase):
|
|||
self.assertSerializedEqual(FoodManager('a', 'b'))
|
||||
self.assertSerializedEqual(FoodManager('x', 'y', c=3, d=4))
|
||||
|
||||
|
||||
def test_serialize_timedelta(self):
|
||||
self.assertSerializedEqual(datetime.timedelta())
|
||||
self.assertSerializedEqual(datetime.timedelta(minutes=42))
|
||||
|
||||
def test_simple_migration(self):
|
||||
"""
|
||||
Tests serializing a simple migration.
|
||||
|
|
Loading…
Reference in New Issue