Being compatible with non-django style chioces

This commit is contained in:
Karim Allah 2011-09-18 19:48:33 +02:00
parent 89c44cd14e
commit adb7bbeea0

View File

@ -139,9 +139,14 @@ class BaseField(object):
def _validate(self, value):
# check choices
if self.choices is not None:
option_keys = [option_key for option_key, option_value in self.choices]
if value not in option_keys:
raise ValidationError("Value must be one of %s." % unicode(option_keys))
if type(choices[0]) is tuple:
option_keys = [option_key for option_key, option_value in self.choices]
if value not in 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
if self.validation is not None: