Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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

…ntation. Thanks jsdalton.

Backport of r16536 from trunk.

git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.3.X@16537 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 220ce42333b8bff16b4b0b434cfc2570dcce9985 1 parent c828cc1
Simon Meers authored July 10, 2011

Showing 1 changed file with 18 additions and 0 deletions. Show diff stats Hide diff stats

  1. 18  docs/ref/contrib/contenttypes.txt
18  docs/ref/contrib/contenttypes.txt
@@ -192,6 +192,15 @@ The ``ContentTypeManager``
192 192
         :class:`~django.contrib.contenttypes.models.ContentType` instance
193 193
         representing that model.
194 194
 
  195
+    .. method:: get_by_natural_key(app_label, model)
  196
+
  197
+        Returns the :class:`~django.contrib.contenttypes.models.ContentType`
  198
+        instance uniquely identified by the given application label and model
  199
+        name. The primary purpose of this method is to allow
  200
+        :class:`~django.contrib.contenttypes.models.ContentType` objects to be
  201
+        referenced via a :ref:`natural key<topics-serialization-natural-keys>`
  202
+        during deserialization.
  203
+
195 204
 The :meth:`~ContentTypeManager.get_for_model()` method is especially
196 205
 useful when you know you need to work with a
197 206
 :class:`ContentType <django.contrib.contenttypes.models.ContentType>` but don't
@@ -285,6 +294,15 @@ model:
285 294
    should evaluate the models you expect to be pointing to and determine
286 295
    which solution will be most effective for your use case.
287 296
 
  297
+.. admonition:: Serializing references to ``ContentType`` objects
  298
+
  299
+   If you're serializing data (for example, when generating
  300
+   :class:`~django.test.TestCase.fixtures`) from a model that implements
  301
+   generic relations, you should probably be using a natural key to uniquely
  302
+   identify related :class:`~django.contrib.contenttypes.models.ContentType`
  303
+   objects. See :ref:`natural keys<topics-serialization-natural-keys>` and
  304
+   :djadminopt:`dumpdata --natural <--natural>` for more information.
  305
+
288 306
 This will enable an API similar to the one used for a normal
289 307
 :class:`~django.db.models.ForeignKey`;
290 308
 each ``TaggedItem`` will have a ``content_object`` field that returns the

0 notes on commit 220ce42

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