Fixed #23316 -- Added datetime.time serialization in migrations.

This commit is contained in:
Lee Sanghyuck 2014-08-19 22:23:29 +09:00 committed by Tim Graham
parent ad9ba9d27b
commit 11d9cbe2f4
4 changed files with 7 additions and 1 deletions

View File

@ -545,6 +545,7 @@ answer newbie questions, and generally made Django that much better:
Bartolome Sanchez Salado <i42sasab@uco.es>
Nick Sandford <nick.sandford@gmail.com>
Mark Sandstrom <mark@deliciouslynerdy.com>
Lee Sanghyuck <shlee322@elab.kr>
Kadesarin Sanjek
Tim Saylor <tim.saylor@gmail.com>
Massimo Scamarcia <massimo.scamarcia@gmail.com>

View File

@ -279,6 +279,10 @@ class MigrationWriter(object):
if isinstance(value, datetime_safe.date):
value_repr = "datetime.%s" % value_repr
return value_repr, set(["import datetime"])
# Times
elif isinstance(value, datetime.time):
value_repr = repr(value)
return value_repr, set(["import datetime"])
# Settings references
elif isinstance(value, SettingsReference):
return "settings.%s" % value.setting_name, set(["from django.conf import settings"])

View File

@ -524,7 +524,7 @@ Django can serialize the following:
- ``int``, ``long``, ``float``, ``bool``, ``str``, ``unicode``, ``bytes``, ``None``
- ``list``, ``set``, ``tuple``, ``dict``
- ``datetime.date`` and ``datetime.datetime`` instances
- ``datetime.date``, ``datetime.time``, and ``datetime.datetime`` instances
- ``decimal.Decimal`` instances
- Any Django field
- Any function or method reference (e.g. ``datetime.datetime.today``)

View File

@ -95,6 +95,7 @@ class WriterTests(TestCase):
self.assertSerializedEqual(datetime.datetime.today)
self.assertSerializedEqual(datetime.date.today())
self.assertSerializedEqual(datetime.date.today)
self.assertSerializedEqual(datetime.datetime.now().time())
with self.assertRaises(ValueError):
self.assertSerializedEqual(datetime.datetime(2012, 1, 1, 1, 1, tzinfo=get_default_timezone()))
safe_date = datetime_safe.date(2014, 3, 31)