Added django style choices

This commit is contained in:
Viktor Kerkez 2010-11-01 14:54:55 +01:00
parent ef15733efe
commit e1282028a5
2 changed files with 5 additions and 6 deletions

View File

@ -100,9 +100,9 @@ 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 value not in self.choices: option_keys = [option_key for option_key, option_value in self.choices]
raise ValidationError("Value must be one of %s." if value not in option_keys:
% unicode(self.choices)) raise ValidationError("Value must be one of %s." % unicode(option_keys))
# check validation argument # check validation argument
if self.validation is not None: if self.validation is not None:

View File

@ -12,7 +12,6 @@ import datetime
import decimal import decimal
import gridfs import gridfs
import warnings import warnings
import types
__all__ = ['StringField', 'IntField', 'FloatField', 'BooleanField', __all__ = ['StringField', 'IntField', 'FloatField', 'BooleanField',