summaryrefslogtreecommitdiff
path: root/docs/ref
diff options
context:
space:
mode:
authorTim Graham <timograham@gmail.com>2016-05-16 11:23:56 -0400
committerTim Graham <timograham@gmail.com>2016-05-16 11:26:13 -0400
commitff1eb0a6deeab6b07f30f11b2a6565ae9ec5556b (patch)
treec346eefb92a2ce28642b7f92a2828688136576a4 /docs/ref
parentdbd72b850b487be37df2940d16697a2d57b73ac6 (diff)
[1.9.x] Removed a redundant example in contenttypes docs.
Backport of aa69f36984adb6cba5763604150d99e89aa1ee71 from master
Diffstat (limited to 'docs/ref')
-rw-r--r--docs/ref/contrib/contenttypes.txt37
1 files changed, 13 insertions, 24 deletions
diff --git a/docs/ref/contrib/contenttypes.txt b/docs/ref/contrib/contenttypes.txt
index f100864236..7860bbdeb2 100644
--- a/docs/ref/contrib/contenttypes.txt
+++ b/docs/ref/contrib/contenttypes.txt
@@ -400,6 +400,14 @@ from ``TaggedItem``::
>>> TaggedItem.objects.filter(bookmarks__url__contains='django')
[<TaggedItem: django>, <TaggedItem: python>]
+Of course, if you don't add the reverse relationship, you can do the
+same types of lookups manually::
+
+ >>> b = Bookmark.objects.get(url='https://www.djangoproject.com/')
+ >>> bookmark_type = ContentType.objects.get_for_model(b)
+ >>> TaggedItem.objects.filter(content_type__pk=bookmark_type.id, object_id=b.id)
+ [<TaggedItem: django>, <TaggedItem: python>]
+
Just as :class:`~django.contrib.contenttypes.fields.GenericForeignKey`
accepts the names of the content-type and object-ID fields as
arguments, so too does
@@ -411,30 +419,11 @@ referred to above used fields named ``content_type_fk`` and
``object_primary_key`` to create its generic foreign key, then a
:class:`.GenericRelation` back to it would need to be defined like so::
- tags = GenericRelation(TaggedItem,
- content_type_field='content_type_fk',
- object_id_field='object_primary_key')
-
-Of course, if you don't add the reverse relationship, you can do the
-same types of lookups manually::
-
- >>> b = Bookmark.objects.get(url='https://www.djangoproject.com/')
- >>> bookmark_type = ContentType.objects.get_for_model(b)
- >>> TaggedItem.objects.filter(content_type__pk=bookmark_type.id,
- ... object_id=b.id)
- [<TaggedItem: django>, <TaggedItem: python>]
-
-Note that if the model in a
-:class:`~django.contrib.contenttypes.fields.GenericRelation` uses a
-non-default value for ``ct_field`` or ``fk_field`` in its
-:class:`~django.contrib.contenttypes.fields.GenericForeignKey` (for example, if
-you had a ``Comment`` model that uses ``ct_field="object_pk"``),
-you'll need to set ``content_type_field`` and/or ``object_id_field`` in
-the :class:`~django.contrib.contenttypes.fields.GenericRelation` to
-match the ``ct_field`` and ``fk_field``, respectively, in the
-:class:`~django.contrib.contenttypes.fields.GenericForeignKey`::
-
- comments = fields.GenericRelation(Comment, object_id_field="object_pk")
+ tags = GenericRelation(
+ TaggedItem,
+ content_type_field='content_type_fk',
+ object_id_field='object_primary_key',
+ )
Note also, that if you delete an object that has a
:class:`~django.contrib.contenttypes.fields.GenericRelation`, any objects