Fixed #11047 -- Clarified the explanation of arguments to GenericForeignKey. Thanks to psmith and timo for their work on the patch.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@13554 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Russell Keith-Magee 2010-08-07 14:56:59 +00:00
parent 50e3aa03e6
commit 103f7f83eb
1 changed files with 11 additions and 7 deletions

View File

@ -324,15 +324,19 @@ same types of lookups manually::
... object_id=b.id) ... object_id=b.id)
[<TaggedItem: django>, <TaggedItem: python>] [<TaggedItem: django>, <TaggedItem: python>]
Note that if the model with a :class:`~django.contrib.contenttypes.generic.GenericForeignKey` Note that if the model in a
that you're referring to uses a non-default value for ``ct_field`` or ``fk_field`` :class:`~django.contrib.contenttypes.generic.GenericRelation` uses a
(e.g. the :mod:`django.contrib.comments` app uses ``ct_field="object_pk"``), non-default value for ``ct_field`` or ``fk_field`` in its
you'll need to pass ``content_type_field`` and ``object_id_field`` to :class:`~django.contrib.contenttypes.generic.GenericForeignKey` (e.g. the
:class:`~django.contrib.contenttypes.generic.GenericRelation`.:: :mod:`django.contrib.comments` app uses ``ct_field="object_pk"``),
you'll need to set ``content_type_field`` and/or ``object_id_field`` in
the :class:`~django.contrib.contenttypes.generic.GenericRelation` to
match the ``ct_field`` and ``fk_field``, respectively, in the
:class:`~django.contrib.contenttypes.generic.GenericForeignKey`::
comments = generic.GenericRelation(Comment, content_type_field="content_type", object_id_field="object_pk") comments = generic.GenericRelation(Comment, object_id_field="object_pk")
Note that if you delete an object that has a Note also, that if you delete an object that has a
:class:`~django.contrib.contenttypes.generic.GenericRelation`, any objects :class:`~django.contrib.contenttypes.generic.GenericRelation`, any objects
which have a :class:`~django.contrib.contenttypes.generic.GenericForeignKey` which have a :class:`~django.contrib.contenttypes.generic.GenericForeignKey`
pointing at it will be deleted as well. In the example above, this means that pointing at it will be deleted as well. In the example above, this means that