mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-11 04:07:39 +03:00
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:
commit
edd9c7de02
|
@ -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()
|
||||
|
||||
|
|
|
@ -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,
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user