aboutsummaryrefslogtreecommitdiffstats
path: root/rest_framework/fields.py
diff options
context:
space:
mode:
authorAlex2013-11-12 23:40:24 +0000
committerAlex2013-11-12 23:40:24 +0000
commit5136798a040fc306a37b562c7cd629ab34bc02e3 (patch)
treeae51dec9e5ee4bcebbd22d1383602d66f06a996b /rest_framework/fields.py
parentd1dc68d7550e90ba56a3122f8de1f38bb5aa1e3a (diff)
parent8552e79d7b62ca7f0edd131d3049ca220d879d48 (diff)
downloaddjango-rest-framework-5136798a040fc306a37b562c7cd629ab34bc02e3.tar.bz2
Merge branch 'master' into allow-aggregate-ordering
Diffstat (limited to 'rest_framework/fields.py')
-rw-r--r--rest_framework/fields.py8
1 files changed, 5 insertions, 3 deletions
diff --git a/rest_framework/fields.py b/rest_framework/fields.py
index e23fc001..6c07dbb3 100644
--- a/rest_framework/fields.py
+++ b/rest_framework/fields.py
@@ -497,6 +497,7 @@ class ChoiceField(WritableField):
}
def __init__(self, choices=(), *args, **kwargs):
+ self.empty = kwargs.pop('empty', '')
super(ChoiceField, self).__init__(*args, **kwargs)
self.choices = choices
if not self.required:
@@ -537,9 +538,10 @@ class ChoiceField(WritableField):
return False
def from_native(self, value):
- if value in validators.EMPTY_VALUES:
- return None
- return super(ChoiceField, self).from_native(value)
+ value = super(ChoiceField, self).from_native(value)
+ if value == self.empty or value in validators.EMPTY_VALUES:
+ return self.empty
+ return value
class EmailField(CharField):