From fc08236ab84ce7c348216e9662ebec4ac0dea9a8 Mon Sep 17 00:00:00 2001 From: mjparker777 Date: Sun, 13 Dec 2015 16:09:56 -0700 Subject: [PATCH] updated timefield also --- rest_framework/fields.py | 3 +++ tests/test_fields.py | 4 +++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/rest_framework/fields.py b/rest_framework/fields.py index fc917e213..53a948c06 100644 --- a/rest_framework/fields.py +++ b/rest_framework/fields.py @@ -1186,6 +1186,9 @@ class TimeField(Field): self.fail('invalid', format=humanized_format) def to_representation(self, value): + if not value: + return None + output_format = getattr(self, 'format', api_settings.TIME_FORMAT) if output_format is None: diff --git a/tests/test_fields.py b/tests/test_fields.py index 71bb70cd8..029a5bddc 100644 --- a/tests/test_fields.py +++ b/tests/test_fields.py @@ -1030,7 +1030,9 @@ class TestTimeField(FieldValues): '99:99': ['Time has wrong format. Use one of these formats instead: hh:mm[:ss[.uuuuuu]].'], } outputs = { - datetime.time(13, 00): '13:00:00' + datetime.time(13, 00): '13:00:00', + None: None, + '': None, } field = serializers.TimeField()