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

Fixed #24566 -- Added support for serializing timedelta

Thanks to knbk for the report.
This commit is contained in:
Baptiste Mispelon 2015-04-02 16:49:41 +02:00
parent 0f941f57ba
commit 30a3c2f74c
3 changed files with 9 additions and 1 deletions

View File

@ -351,6 +351,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"}

View File

@ -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`).

View File

@ -351,6 +351,10 @@ class WriterTests(TestCase):
self.assertSerializedEqual(frozenset())
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):
"""
Tests serializing a simple migration.