mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-06 05:20:12 +03:00
Merge 864335d9b3
into 4f1506c77e
This commit is contained in:
commit
f21aa33a90
|
@ -910,7 +910,7 @@ class DateField(Field):
|
||||||
self.fail('invalid', format=humanized_format)
|
self.fail('invalid', format=humanized_format)
|
||||||
|
|
||||||
def to_representation(self, value):
|
def to_representation(self, value):
|
||||||
if self.format is None:
|
if self.format or value is None:
|
||||||
return value
|
return value
|
||||||
|
|
||||||
# Applying a `DateField` to a datetime value is almost always
|
# Applying a `DateField` to a datetime value is almost always
|
||||||
|
@ -1024,8 +1024,10 @@ class ChoiceField(Field):
|
||||||
def to_representation(self, value):
|
def to_representation(self, value):
|
||||||
if value in ('', None):
|
if value in ('', None):
|
||||||
return value
|
return value
|
||||||
return self.choice_strings_to_values[six.text_type(value)]
|
try:
|
||||||
|
return self.choice_strings_to_values[six.text_type(value)]
|
||||||
|
except KeyError:
|
||||||
|
return value
|
||||||
|
|
||||||
class MultipleChoiceField(ChoiceField):
|
class MultipleChoiceField(ChoiceField):
|
||||||
default_error_messages = {
|
default_error_messages = {
|
||||||
|
@ -1051,10 +1053,12 @@ class MultipleChoiceField(ChoiceField):
|
||||||
])
|
])
|
||||||
|
|
||||||
def to_representation(self, value):
|
def to_representation(self, value):
|
||||||
return set([
|
if value in ('', None):
|
||||||
self.choice_strings_to_values[six.text_type(item)] for item in value
|
return value
|
||||||
])
|
try:
|
||||||
|
return self.choice_strings_to_values[six.text_type(value)]
|
||||||
|
except KeyError:
|
||||||
|
return value
|
||||||
|
|
||||||
# File types...
|
# File types...
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user