Commits

Anonymous committed c6adabe

[1.3.X] Fixed #16000 -- reference natural keys in contenttypes documentation. Thanks jsdalton.

Backport of r16536 from trunk.

Comments (0)

Files changed (1)

docs/ref/contrib/contenttypes.txt

         :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
    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
 :class:`~django.db.models.ForeignKey`;
 each ``TaggedItem`` will have a ``content_object`` field that returns the
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.