mirror of
https://github.com/django/django.git
synced 2024-11-29 22:56:46 +01:00
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):
|
||||
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`).
|
||||
|
@ -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.
|
||||
|
Loading…
Reference in New Issue
Block a user