Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[1.0.X] Fixed #10367: Added note to generic-relation docs explaining …

…when it's necessary to pass in field names to create a reverse relation. Backport of [10273] from trunk.

git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.0.X@10274 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 550dd623007526c206e731b963de0ff8ce0ae253 1 parent 8c77663
@ubernostrum ubernostrum authored
Showing with 14 additions and 1 deletion.
  1. +14 −1 docs/ref/contrib/contenttypes.txt
View
15 docs/ref/contrib/contenttypes.txt
@@ -303,7 +303,20 @@ be used to retrieve their associated ``TaggedItems``::
>>> b.tags.all()
[<TaggedItem: django>, <TaggedItem: python>]
-If you don't add the reverse relationship, you can do the lookup manually::
+Just as :class:`django.contrib.contenttypes.generic.GenericForeignKey`
+accepts the names of the content-type and object-ID fields as
+arguments, so too does ``GenericRelation``; if the model which has the
+generic foreign key is using non-default names for those fields, you
+must pass the names of the fields when setting up a
+``GenericRelation`` to it. For example, if the ``TaggedItem`` model
+referred to above used fields named ``content_type_fk`` and
+``object_primary_key`` to create its generic foreign key, then a
+``GenericRelation`` back to it would need to be defined like so::
+
+ tags = generic.GenericRelation('content_type_fk', '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='http://www.djangoproject.com/')
>>> bookmark_type = ContentType.objects.get_for_model(b)
Please sign in to comment.
Something went wrong with that request. Please try again.