Make validation-lists possible. Example:
class Doc(Document): country = StringField(validation=['DE', 'AT', 'CH'])
This commit is contained in:
parent
48facec524
commit
f3ca9fa4c5
@ -78,7 +78,10 @@ class BaseField(object):
|
|||||||
def validate(self, value):
|
def validate(self, value):
|
||||||
"""Perform validation on a value.
|
"""Perform validation on a value.
|
||||||
"""
|
"""
|
||||||
if self.validation is not None and not self.validation(value):
|
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.')
|
raise ValidationError('Value does not match custom validation method.')
|
||||||
|
|
||||||
class ObjectIdField(BaseField):
|
class ObjectIdField(BaseField):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user