Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding "Using an Embedded Model as an abstract base class" to the docs. #92

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions docs/source/topics/embedded-models.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down