DateField.to_representation unicode compatibility

This commit is contained in:
Mikalai Radchuk 2016-01-10 23:50:11 +03:00
parent 057cf13578
commit 6b207d93d6
2 changed files with 3 additions and 2 deletions

View File

@ -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()

View File

@ -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,
}