Make validation-lists possible. Example:
class Doc(Document): country = StringField(validation=['DE', 'AT', 'CH'])
This commit is contained in:
parent
48facec524
commit
f3ca9fa4c5
@ -78,8 +78,11 @@ class BaseField(object):
|
||||
def validate(self, value):
|
||||
"""Perform validation on a value.
|
||||
"""
|
||||
if self.validation is not None and not self.validation(value):
|
||||
raise ValidationError('Value does not match custom validation method.')
|
||||
if self.validation is not None:
|
||||
if isinstance(self.validation, list):
|
||||
raise ValidationError('Value not in validation list.')
|
||||
elif callable(self.validation) and not self.validation(value):
|
||||
raise ValidationError('Value does not match custom validation method.')
|
||||
|
||||
class ObjectIdField(BaseField):
|
||||
"""An field wrapper around MongoDB's ObjectIds.
|
||||
|
Loading…
x
Reference in New Issue
Block a user