Implemented Choices for GenericReferenceFields
Refs mongoengine/mongoengine#13
This commit is contained in:
@@ -223,11 +223,10 @@ class BaseField(object):
|
||||
pass
|
||||
|
||||
def _validate(self, value):
|
||||
from mongoengine import EmbeddedDocument
|
||||
|
||||
from mongoengine import Document, EmbeddedDocument
|
||||
# check choices
|
||||
if self.choices:
|
||||
is_cls = isinstance(value, EmbeddedDocument)
|
||||
is_cls = isinstance(value, (Document, EmbeddedDocument))
|
||||
value_to_check = value.__class__ if is_cls else value
|
||||
err_msg = 'an instance' if is_cls else 'one'
|
||||
if isinstance(self.choices[0], (list, tuple)):
|
||||
|
||||
@@ -441,6 +441,9 @@ class GenericEmbeddedDocumentField(BaseField):
|
||||
:class:`~mongoengine.EmbeddedDocument` to be stored.
|
||||
|
||||
Only valid values are subclasses of :class:`~mongoengine.EmbeddedDocument`.
|
||||
|
||||
..note :: You can use the choices param to limit the acceptable
|
||||
EmbeddedDocument types
|
||||
"""
|
||||
|
||||
def prepare_query_value(self, op, value):
|
||||
@@ -701,6 +704,8 @@ class GenericReferenceField(BaseField):
|
||||
..note :: Any documents used as a generic reference must be registered in the
|
||||
document registry. Importing the model will automatically register it.
|
||||
|
||||
..note :: You can use the choices param to limit the acceptable Document types
|
||||
|
||||
.. versionadded:: 0.3
|
||||
"""
|
||||
|
||||
|
||||
Reference in New Issue
Block a user