mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-26 03:23:59 +03:00
Make ChoiceField.from_native() follow IntegerField behaviour on empty values
This commit is contained in:
parent
ac4cd50a7b
commit
11071499a7
|
@ -514,6 +514,11 @@ class ChoiceField(WritableField):
|
|||
return True
|
||||
return False
|
||||
|
||||
def from_native(self, value):
|
||||
if value in validators.EMPTY_VALUES:
|
||||
return None
|
||||
return super(ChoiceField, self).from_native(value)
|
||||
|
||||
|
||||
class EmailField(CharField):
|
||||
type_name = 'EmailField'
|
||||
|
|
|
@ -688,6 +688,14 @@ class ChoiceFieldTests(TestCase):
|
|||
f = serializers.ChoiceField(required=False, choices=self.SAMPLE_CHOICES)
|
||||
self.assertEqual(f.choices, models.fields.BLANK_CHOICE_DASH + self.SAMPLE_CHOICES)
|
||||
|
||||
def test_from_native_empty(self):
|
||||
"""
|
||||
Make sure from_native() returns None on empty param.
|
||||
"""
|
||||
f = serializers.ChoiceField(choices=self.SAMPLE_CHOICES)
|
||||
result = f.from_native('')
|
||||
self.assertEqual(result, None)
|
||||
|
||||
|
||||
class EmailFieldTests(TestCase):
|
||||
"""
|
||||
|
|
Loading…
Reference in New Issue
Block a user