~ubuntu-branches/ubuntu/quantal/python-django/quantal-security

« back to all changes in this revision

Viewing changes to docs/ref/contrib/contenttypes.txt

  • Committer: Bazaar Package Importer
  • Author(s): Jamie Strandboge
  • Date: 2010-10-12 11:34:35 UTC
  • mfrom: (4.4.9 sid)
  • mto: This revision was merged to the branch mainline in revision 30.
  • Revision ID: james.westby@ubuntu.com-20101012113435-5rk3p18nyanuhj6g
* SECURITY UPDATE: XSS in CSRF protections. New upstream release
  - CVE-2010-3082
* debian/patches/01_disable_url_verify_regression_tests.diff:
  - updated to disable another test that fails without internet connection
  - patch based on work by Kai Kasurinen and Krzysztof Klimonda
* debian/control: don't Build-Depends on locales-all, which doesn't exist
  in maverick

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
.. _ref-contrib-contenttypes:
2
 
 
3
1
==========================
4
2
The contenttypes framework
5
3
==========================
114
112
 
115
113
    Takes a set of valid :ref:`lookup arguments <field-lookups-intro>` for the
116
114
    model the :class:`~django.contrib.contenttypes.models.ContentType`
117
 
    represents, and does :ref:`a get() lookup <get-kwargs>` on that model,
 
115
    represents, and does :lookup:`a get() lookup <get>` on that model,
118
116
    returning the corresponding object.
119
117
 
120
118
.. method:: models.ContentType.model_class()
324
322
    ...                           object_id=b.id)
325
323
    [<TaggedItem: django>, <TaggedItem: python>]
326
324
 
327
 
Note that if the model with a :class:`~django.contrib.contenttypes.generic.GenericForeignKey`
328
 
that you're referring to uses a non-default value for ``ct_field`` or ``fk_field``
329
 
(e.g. the :mod:`django.contrib.comments` app uses ``ct_field="object_pk"``),
330
 
you'll need to pass ``content_type_field`` and ``object_id_field`` to
331
 
:class:`~django.contrib.contenttypes.generic.GenericRelation`.::
332
 
 
333
 
        comments = generic.GenericRelation(Comment, content_type_field="content_type", object_id_field="object_pk")
334
 
 
335
 
Note that if you delete an object that has a
 
325
Note that if the model in a
 
326
:class:`~django.contrib.contenttypes.generic.GenericRelation` uses a
 
327
non-default value for ``ct_field`` or ``fk_field`` in its
 
328
:class:`~django.contrib.contenttypes.generic.GenericForeignKey` (e.g. the
 
329
:mod:`django.contrib.comments` app uses ``ct_field="object_pk"``),
 
330
you'll need to set ``content_type_field`` and/or ``object_id_field`` in
 
331
the :class:`~django.contrib.contenttypes.generic.GenericRelation` to
 
332
match the ``ct_field`` and ``fk_field``, respectively, in the
 
333
:class:`~django.contrib.contenttypes.generic.GenericForeignKey`::
 
334
 
 
335
        comments = generic.GenericRelation(Comment, object_id_field="object_pk")
 
336
 
 
337
Note also, that if you delete an object that has a
336
338
:class:`~django.contrib.contenttypes.generic.GenericRelation`, any objects
337
339
which have a :class:`~django.contrib.contenttypes.generic.GenericForeignKey`
338
340
pointing at it will be deleted as well. In the example above, this means that
342
344
Generic relations and aggregation
343
345
---------------------------------
344
346
 
345
 
:ref:`Django's database aggregation API <topics-db-aggregation>`
 
347
:doc:`Django's database aggregation API </topics/db/aggregation>`
346
348
doesn't work with a
347
349
:class:`~django.contrib.contenttypes.generic.GenericRelation`. For example, you
348
350
might be tempted to try something like::
361
363
:class:`~django.contrib.contenttypes.generic.GenericInlineFormSet`
362
364
and :class:`~django.contrib.contenttypes.generic.GenericInlineModelAdmin`.
363
365
This enables the use of generic relations in forms and the admin. See the
364
 
:ref:`model formset <topics-forms-modelforms>` and
365
 
:ref:`admin <ref-contrib-admin>` documentation for more information.
 
366
:doc:`model formset </topics/forms/modelforms>` and
 
367
:doc:`admin </ref/contrib/admin/index>` documentation for more information.
366
368
 
367
369
.. class:: generic.GenericInlineModelAdmin
368
370
 
369
371
    The :class:`~django.contrib.contenttypes.generic.GenericInlineModelAdmin`
370
372
    class inherits all properties from an
371
 
    :class:`~django.contrib.admin.options.InlineModelAdmin` class. However,
 
373
    :class:`~django.contrib.admin.InlineModelAdmin` class. However,
372
374
    it adds a couple of its own for working with the generic relation:
373
375
 
374
376
    .. attribute:: generic.GenericInlineModelAdmin.ct_field