Being compatible with non-django style chioces
This commit is contained in:
parent
89c44cd14e
commit
adb7bbeea0
@ -139,9 +139,14 @@ class BaseField(object):
|
|||||||
def _validate(self, value):
|
def _validate(self, value):
|
||||||
# check choices
|
# check choices
|
||||||
if self.choices is not None:
|
if self.choices is not None:
|
||||||
|
if type(choices[0]) is tuple:
|
||||||
option_keys = [option_key for option_key, option_value in self.choices]
|
option_keys = [option_key for option_key, option_value in self.choices]
|
||||||
if value not in option_keys:
|
if value not in option_keys:
|
||||||
raise ValidationError("Value must be one of %s." % unicode(option_keys))
|
raise ValidationError("Value must be one of %s." % unicode(option_keys))
|
||||||
|
else:
|
||||||
|
if value not in self.choices:
|
||||||
|
raise ValidationError("Value must be one of %s." % unicode(self.choices))
|
||||||
|
|
||||||
|
|
||||||
# check validation argument
|
# check validation argument
|
||||||
if self.validation is not None:
|
if self.validation is not None:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user