From f3ca9fa4c5052c997790077b18246d9c7c3468d0 Mon Sep 17 00:00:00 2001 From: Florian Schlachter Date: Fri, 16 Apr 2010 18:00:51 +0200 Subject: [PATCH] Make validation-lists possible. Example: class Doc(Document): country = StringField(validation=['DE', 'AT', 'CH']) --- mongoengine/base.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/mongoengine/base.py b/mongoengine/base.py index a83f3e7b..41cbed58 100644 --- a/mongoengine/base.py +++ b/mongoengine/base.py @@ -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.