|
@@ -450,18 +450,12 @@ signal.
|
|
|
Generic relations and aggregation
|
|
|
---------------------------------
|
|
|
|
|
|
-:doc:`Django's database aggregation API </topics/db/aggregation>`
|
|
|
-doesn't work with a
|
|
|
+:doc:`Django's database aggregation API </topics/db/aggregation>` works with a
|
|
|
:class:`~django.contrib.contenttypes.fields.GenericRelation`. For example, you
|
|
|
-might be tempted to try something like::
|
|
|
+can find out how many tags all the bookmarks have::
|
|
|
|
|
|
- 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
|
|
|
-:meth:`~django.db.models.query.QuerySet.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.
|
|
|
+ >>> Bookmark.objects.aggregate(Count('tags'))
|
|
|
+ {'tags__count': 3}
|
|
|
|
|
|
.. module:: django.contrib.contenttypes.forms
|
|
|
|