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)
|
||||
|
||||
def to_representation(self, value):
|
||||
if self.format is None:
|
||||
if self.format or value is None:
|
||||
return value
|
||||
|
||||
# Applying a `DateField` to a datetime value is almost always
|
||||
|
@ -1024,8 +1024,10 @@ class ChoiceField(Field):
|
|||
def to_representation(self, value):
|
||||
if value in ('', None):
|
||||
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):
|
||||
default_error_messages = {
|
||||
|
@ -1051,10 +1053,12 @@ class MultipleChoiceField(ChoiceField):
|
|||
])
|
||||
|
||||
def to_representation(self, value):
|
||||
return set([
|
||||
self.choice_strings_to_values[six.text_type(item)] for item in value
|
||||
])
|
||||
|
||||
if value in ('', None):
|
||||
return value
|
||||
try:
|
||||
return self.choice_strings_to_values[six.text_type(value)]
|
||||
except KeyError:
|
||||
return value
|
||||
|
||||
# File types...
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user