From 6b207d93d69c1576ae3d29230b393c566855c577 Mon Sep 17 00:00:00 2001 From: Mikalai Radchuk Date: Sun, 10 Jan 2016 23:50:11 +0300 Subject: [PATCH] DateField.to_representation unicode compatibility --- rest_framework/fields.py | 2 +- tests/test_fields.py | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/rest_framework/fields.py b/rest_framework/fields.py index 7bac2a21f..deca9d90d 100644 --- a/rest_framework/fields.py +++ b/rest_framework/fields.py @@ -1139,7 +1139,7 @@ class DateField(Field): ) if output_format.lower() == ISO_8601: - if (isinstance(value, str)): + if isinstance(value, six.string_types): value = datetime.datetime.strptime(value, '%Y-%m-%d').date() return value.isoformat() diff --git a/tests/test_fields.py b/tests/test_fields.py index 029a5bddc..4b3a36f03 100644 --- a/tests/test_fields.py +++ b/tests/test_fields.py @@ -6,7 +6,7 @@ from decimal import Decimal import django import pytest from django.http import QueryDict -from django.utils import timezone +from django.utils import six, timezone import rest_framework from rest_framework import serializers @@ -895,6 +895,7 @@ class TestDateField(FieldValues): outputs = { datetime.date(2001, 1, 1): '2001-01-01', '2001-01-01': '2001-01-01', + six.text_type('2016-01-10'): '2016-01-10', None: None, '': None, }