From aad1ee796cf7734fbfb3cf52d48a5e8bb4ef5f13 Mon Sep 17 00:00:00 2001 From: Nolhian Date: Wed, 30 Nov 2011 11:34:44 +0100 Subject: [PATCH] Adding "Using an Embedded Model as an abstract base class" to the docs. --- docs/source/topics/embedded-models.rst | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/docs/source/topics/embedded-models.rst b/docs/source/topics/embedded-models.rst index a71082cd..e01144b9 100644 --- a/docs/source/topics/embedded-models.rst +++ b/docs/source/topics/embedded-models.rst @@ -90,6 +90,27 @@ Embedded objects are represented as subobjects on MongoDB:: ] } +Sometimes you just want the Embedded Model to be used as a base class +for other models. If that is the case, you don't want the model to +create a collection of his own in the database. +This is possible by using it as an abstract base class:: + + from djangotoolbox.fields import ListField, EmbeddedModelField + + class Comment(models.Model): + text = models.TextField() + + class Meta: + abstract = True + + class Post(models.Model): + ... + comments = ListField(EmbeddedModelField(Comment)) + +Note that this is slightly different than before. The EmbeddedModelField +argument is no longer a string but the class itself. That means that you +have to declare your abstract base class first. + Generic Embedding ----------------- Similar to Django's `generic relations`_, it's possible to embed objects of any