Merge pull request #3819 from m1kola/bug/DateField-to_representation-unicode-compatibility

PY2: DateField.to_representation can't work with unicode value
This commit is contained in:
Xavier Ordoquy 2016-01-11 11:29:50 +01:00
commit edd9c7de02
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,
}