mirror of https://github.com/django/django.git
Fixed #23316 -- Added datetime.time serialization in migrations.
This commit is contained in:
parent
ad9ba9d27b
commit
11d9cbe2f4
1
AUTHORS
1
AUTHORS
|
@ -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>
|
||||
|
|
|
@ -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"])
|
||||
|
|
|
@ -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``)
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue