Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Browse files

[1.3.X] Fixed #16000 -- reference natural keys in contenttypes docume…

…ntation. Thanks jsdalton.

Backport of r16536 from trunk.

git-svn-id: bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
1 parent c828cc1 commit 220ce42333b8bff16b4b0b434cfc2570dcce9985 @DrMeers DrMeers committed
Showing with 18 additions and 0 deletions.
  1. +18 −0 docs/ref/contrib/contenttypes.txt
18 docs/ref/contrib/contenttypes.txt
@@ -192,6 +192,15 @@ The ``ContentTypeManager``
:class:`~django.contrib.contenttypes.models.ContentType` instance
representing that model.
+ .. method:: get_by_natural_key(app_label, model)
+ Returns the :class:`~django.contrib.contenttypes.models.ContentType`
+ instance uniquely identified by the given application label and model
+ name. The primary purpose of this method is to allow
+ :class:`~django.contrib.contenttypes.models.ContentType` objects to be
+ referenced via a :ref:`natural key<topics-serialization-natural-keys>`
+ during deserialization.
The :meth:`~ContentTypeManager.get_for_model()` method is especially
useful when you know you need to work with a
:class:`ContentType <django.contrib.contenttypes.models.ContentType>` but don't
@@ -285,6 +294,15 @@ model:
should evaluate the models you expect to be pointing to and determine
which solution will be most effective for your use case.
+.. admonition:: Serializing references to ``ContentType`` objects
+ If you're serializing data (for example, when generating
+ :class:`~django.test.TestCase.fixtures`) from a model that implements
+ generic relations, you should probably be using a natural key to uniquely
+ identify related :class:`~django.contrib.contenttypes.models.ContentType`
+ objects. See :ref:`natural keys<topics-serialization-natural-keys>` and
+ :djadminopt:`dumpdata --natural <--natural>` for more information.
This will enable an API similar to the one used for a normal
each ``TaggedItem`` will have a ``content_object`` field that returns the

0 comments on commit 220ce42

Please sign in to comment.
Something went wrong with that request. Please try again.