Ticket #16000: natural_keys_in_contenttype_docs.diff

File natural_keys_in_contenttype_docs.diff, 1.9 KB (added by Jim Dalton, 14 years ago)
  • docs/ref/contrib/contenttypes.txt

     
    191191        Takes either a model class or an instance of a model, and returns the
    192192        :class:`~django.contrib.contenttypes.models.ContentType` instance
    193193        representing that model.
     194   
     195    .. method:: get_by_natural_key(app_label, model)
    194196
     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
    195204The :meth:`~ContentTypeManager.get_for_model()` method is especially
    196205useful when you know you need to work with a
    197206:class:`ContentType <django.contrib.contenttypes.models.ContentType>` but don't
     
    285294   should evaluate the models you expect to be pointing to and determine
    286295   which solution will be most effective for your use case.
    287296
     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 generic
     301   relations, you should probably be using a natural key to uniquely identify
     302   related :class:`~django.contrib.contenttypes.models.ContentType` objects. See
     303   :ref:`natural keys<topics-serialization-natural-keys>` and
     304   :djadminopt:`dumpdata --natural <--natural>` for more information.
     305
    288306This will enable an API similar to the one used for a normal
    289307:class:`~django.db.models.ForeignKey`;
    290308each ``TaggedItem`` will have a ``content_object`` field that returns the
Back to Top