Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
django-rest-framework
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
django-rest-framework
Commits
11071499
Commit
11071499
authored
Aug 29, 2013
by
Mathieu Pillard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make ChoiceField.from_native() follow IntegerField behaviour on empty values
parent
ac4cd50a
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
0 deletions
+13
-0
rest_framework/fields.py
+5
-0
rest_framework/tests/test_fields.py
+8
-0
No files found.
rest_framework/fields.py
View file @
11071499
...
...
@@ -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'
...
...
rest_framework/tests/test_fields.py
View file @
11071499
...
...
@@ -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
):
"""
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment