Skip to content

Commit

Permalink
DateField.to_representation unicode compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
m1kola committed Jan 11, 2016
1 parent 057cf13 commit 6b207d9
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion rest_framework/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -1139,7 +1139,7 @@ def to_representation(self, value):
)

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

Expand Down
3 changes: 2 additions & 1 deletion tests/test_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
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
Expand Down Expand Up @@ -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,
}
Expand Down

0 comments on commit 6b207d9

Please sign in to comment.