Dynamic fields are now validated on save
(MongoEngine/mongoengine#153) (MongoEngine/mongoengine#154)
This commit is contained in:
@@ -245,6 +245,9 @@ class BaseDocument(object):
|
||||
# Get a list of tuples of field names and their current values
|
||||
fields = [(field, self._data.get(name))
|
||||
for name, field in self._fields.items()]
|
||||
if self._dynamic:
|
||||
fields += [(field, self._data.get(name))
|
||||
for name, field in self._dynamic_fields.items()]
|
||||
|
||||
EmbeddedDocumentField = _import_class("EmbeddedDocumentField")
|
||||
GenericEmbeddedDocumentField = _import_class("GenericEmbeddedDocumentField")
|
||||
|
||||
@@ -564,6 +564,10 @@ class DynamicField(BaseField):
|
||||
return StringField().prepare_query_value(op, value)
|
||||
return self.to_mongo(value)
|
||||
|
||||
def validate(self, value, clean=True):
|
||||
if hasattr(value, "validate"):
|
||||
value.validate(clean=clean)
|
||||
|
||||
|
||||
class ListField(ComplexBaseField):
|
||||
"""A list field that wraps a standard field, allowing multiple instances
|
||||
|
||||
Reference in New Issue
Block a user