improve documentation regarding allow_inheritance

This commit is contained in:
Stefan Wojcik 2016-12-08 23:06:17 -05:00
parent 5b7b65a750
commit 4e1145d890
2 changed files with 10 additions and 6 deletions

View File

@ -46,6 +46,7 @@ class DocumentMetaclass(type):
attrs['_meta'] = meta attrs['_meta'] = meta
attrs['_meta']['abstract'] = False # 789: EmbeddedDocument shouldn't inherit abstract attrs['_meta']['abstract'] = False # 789: EmbeddedDocument shouldn't inherit abstract
# If allow_inheritance is True, add a "_cls" string field to the attrs
if attrs['_meta'].get('allow_inheritance'): if attrs['_meta'].get('allow_inheritance'):
StringField = _import_class('StringField') StringField = _import_class('StringField')
attrs['_cls'] = StringField() attrs['_cls'] = StringField()
@ -270,6 +271,11 @@ class TopLevelDocumentMetaclass(DocumentMetaclass):
'index_drop_dups': False, 'index_drop_dups': False,
'index_opts': None, 'index_opts': None,
'delete_rules': None, 'delete_rules': None,
# allow_inheritance can be True, False, and None. True means
# "allow inheritance", False means "don't allow inheritance",
# None means "do whatever your parent does, or don't allow
# inheritance if you're a top-level class".
'allow_inheritance': None, 'allow_inheritance': None,
} }
attrs['_is_base_cls'] = True attrs['_is_base_cls'] = True

View File

@ -49,9 +49,8 @@ class EmbeddedDocument(BaseDocument):
to create a specialised version of the embedded document that will be to create a specialised version of the embedded document that will be
stored in the same collection. To facilitate this behaviour a `_cls` stored in the same collection. To facilitate this behaviour a `_cls`
field is added to documents (hidden though the MongoEngine interface). field is added to documents (hidden though the MongoEngine interface).
To disable this behaviour and remove the dependence on the presence of To enable this behaviour set :attr:`allow_inheritance` to ``True`` in the
`_cls` set :attr:`allow_inheritance` to ``False`` in the :attr:`meta` :attr:`meta` dictionary.
dictionary.
""" """
__slots__ = ('_instance', ) __slots__ = ('_instance', )
@ -107,9 +106,8 @@ class Document(BaseDocument):
create a specialised version of the document that will be stored in the create a specialised version of the document that will be stored in the
same collection. To facilitate this behaviour a `_cls` same collection. To facilitate this behaviour a `_cls`
field is added to documents (hidden though the MongoEngine interface). field is added to documents (hidden though the MongoEngine interface).
To disable this behaviour and remove the dependence on the presence of To enable this behaviourset :attr:`allow_inheritance` to ``True`` in the
`_cls` set :attr:`allow_inheritance` to ``False`` in the :attr:`meta` :attr:`meta` dictionary.
dictionary.
A :class:`~mongoengine.Document` may use a **Capped Collection** by A :class:`~mongoengine.Document` may use a **Capped Collection** by
specifying :attr:`max_documents` and :attr:`max_size` in the :attr:`meta` specifying :attr:`max_documents` and :attr:`max_size` in the :attr:`meta`