From 4e1145d890e102dd090f01379b48cee7fee1a281 Mon Sep 17 00:00:00 2001 From: Stefan Wojcik Date: Thu, 8 Dec 2016 23:06:17 -0500 Subject: [PATCH] improve documentation regarding allow_inheritance --- mongoengine/base/metaclasses.py | 6 ++++++ mongoengine/document.py | 10 ++++------ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/mongoengine/base/metaclasses.py b/mongoengine/base/metaclasses.py index 55d3e88b..97305fd5 100644 --- a/mongoengine/base/metaclasses.py +++ b/mongoengine/base/metaclasses.py @@ -46,6 +46,7 @@ class DocumentMetaclass(type): attrs['_meta'] = meta 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'): StringField = _import_class('StringField') attrs['_cls'] = StringField() @@ -270,6 +271,11 @@ class TopLevelDocumentMetaclass(DocumentMetaclass): 'index_drop_dups': False, 'index_opts': 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, } attrs['_is_base_cls'] = True diff --git a/mongoengine/document.py b/mongoengine/document.py index 8be78c88..e86a45d9 100644 --- a/mongoengine/document.py +++ b/mongoengine/document.py @@ -49,9 +49,8 @@ class EmbeddedDocument(BaseDocument): to create a specialised version of the embedded document that will be stored in the same collection. To facilitate this behaviour a `_cls` field is added to documents (hidden though the MongoEngine interface). - To disable this behaviour and remove the dependence on the presence of - `_cls` set :attr:`allow_inheritance` to ``False`` in the :attr:`meta` - dictionary. + To enable this behaviour set :attr:`allow_inheritance` to ``True`` in the + :attr:`meta` dictionary. """ __slots__ = ('_instance', ) @@ -107,9 +106,8 @@ class Document(BaseDocument): create a specialised version of the document that will be stored in the same collection. To facilitate this behaviour a `_cls` field is added to documents (hidden though the MongoEngine interface). - To disable this behaviour and remove the dependence on the presence of - `_cls` set :attr:`allow_inheritance` to ``False`` in the :attr:`meta` - dictionary. + To enable this behaviourset :attr:`allow_inheritance` to ``True`` in the + :attr:`meta` dictionary. A :class:`~mongoengine.Document` may use a **Capped Collection** by specifying :attr:`max_documents` and :attr:`max_size` in the :attr:`meta`