﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
10621	Add a way to have an aggregate() result as a queryset	Malcolm Tredinnick	nobody	"If one is trying to construct a complex queryset, involving nesting other querysets, there's currently no way to include the results of an `aggregate()` call. For example, consider
{{{
#!python
class Item(models.Model):
   name = models.CharField(max_length=10)
}}}

If I want to include the number of Items in some other queryset, such as 
{{{
#!python
Foo.objects.filter(items__in=[...]).annotate(num=Count(""items"").filter(num=item_count)
}}}
We can't write item_count (which would be `Items.objects.aggregate(Count(""id""))`) as an inner queryset here, since the `aggregate()` call returns a dictionary, not a queryset.

The return value of `aggregate()` is fine, but this ticket is about adding a version that does return a queryset. Right now, there's no way to fake this with `annotate(...).values(...)` since that always introduces a `GROUP BY` clause and the whole point is not to group by anything.

Not sure whether adding a parameter to `aggregate()` is the right idea, or adding something to the `annotate()` route to specify ""no grouping whatsoever"". This is all 1.2 timeframe stuff, but it's something to think about."	New feature	closed	Database layer (models, ORM)		Normal	duplicate			Accepted	0	0	0	0	0	0
