Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed #11039: documented that aggregation and generic relations don't…

… mix. Thanks, psmith.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@10781 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit d987b378ceaa546d43f42588564515aadb0c9233 1 parent 5bdee25
@jacobian jacobian authored
Showing with 15 additions and 0 deletions.
  1. +15 −0 docs/ref/contrib/contenttypes.txt
View
15 docs/ref/contrib/contenttypes.txt
@@ -339,6 +339,21 @@ pointing at it will be deleted as well. In the example above, this means that
if a ``Bookmark`` object were deleted, any ``TaggedItem`` objects pointing at
it would be deleted at the same time.
+Generic relations and aggregation
+---------------------------------
+
+:ref:`Django's database aggregation API <topics-db-aggregation`
+doesn't work with a
+:class:`~django.contrib.contenttypes.generic.GenericRelation`. For example, you
+might be tempted to try something like::
+
+ Bookmark.objects.aggregate(Count('tags'))
+
+This will not work correctly, however. The generic relation adds extra filters
+to the queryset to ensure the correct content type, but the ``aggregate`` method
+doesn't take them into account. For now, if you need aggregates on generic
+relations, you'll need to calculate them without using the aggregation API.
+
Generic relations in forms and admin
------------------------------------
Please sign in to comment.
Something went wrong with that request. Please try again.