From 11d9cbe2f46583716aed4859f180a973bf2d5cf4 Mon Sep 17 00:00:00 2001 From: Lee Sanghyuck Date: Tue, 19 Aug 2014 22:23:29 +0900 Subject: [PATCH] Fixed #23316 -- Added datetime.time serialization in migrations. --- AUTHORS | 1 + django/db/migrations/writer.py | 4 ++++ docs/topics/migrations.txt | 2 +- tests/migrations/test_writer.py | 1 + 4 files changed, 7 insertions(+), 1 deletion(-) diff --git a/AUTHORS b/AUTHORS index 279c1a4dd4..0df78dac54 100644 --- a/AUTHORS +++ b/AUTHORS @@ -545,6 +545,7 @@ answer newbie questions, and generally made Django that much better: Bartolome Sanchez Salado Nick Sandford Mark Sandstrom + Lee Sanghyuck Kadesarin Sanjek Tim Saylor Massimo Scamarcia diff --git a/django/db/migrations/writer.py b/django/db/migrations/writer.py index 593bff902d..ac5da0953b 100644 --- a/django/db/migrations/writer.py +++ b/django/db/migrations/writer.py @@ -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"]) diff --git a/docs/topics/migrations.txt b/docs/topics/migrations.txt index ec462ea0fa..0aad1a5064 100644 --- a/docs/topics/migrations.txt +++ b/docs/topics/migrations.txt @@ -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``) diff --git a/tests/migrations/test_writer.py b/tests/migrations/test_writer.py index 64368af03e..3839f78cbd 100644 --- a/tests/migrations/test_writer.py +++ b/tests/migrations/test_writer.py @@ -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)