summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorSimon Meers <simon@simonmeers.com>2011-07-10 21:52:03 +0000
committerSimon Meers <simon@simonmeers.com>2011-07-10 21:52:03 +0000
commit86ac8c132799d6adb0a89f19972c9fae096f7772 (patch)
treeccaeea0dcee91a518e4067563e5adbb212183aef /docs
parent4d920c5ecdac9ebb96ff88955a0ff0b7a3616fc6 (diff)
Fixed #16000 -- reference natural keys in contenttypes documentation. Thanks jsdalton.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@16536 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'docs')
-rw-r--r--docs/ref/contrib/contenttypes.txt18
1 files changed, 18 insertions, 0 deletions
diff --git a/docs/ref/contrib/contenttypes.txt b/docs/ref/contrib/contenttypes.txt
index cafbaf4a62..e97116736d 100644
--- a/docs/ref/contrib/contenttypes.txt
+++ b/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
:class:`~django.db.models.ForeignKey`;
each ``TaggedItem`` will have a ``content_object`` field that returns the