home / django_tickets / tickets

tickets: 10621

This data as json

id created changetime last_pulled_from_trac stage status component type severity version resolution summary description owner reporter keywords easy has_patch needs_better_patch needs_tests needs_docs ui_ux
10621 2009-03-25 09:35:49 2011-04-02 02:25:30 2022-03-06 03:47:47.697469 Accepted new Database layer (models, ORM) New feature Normal     Add a way to have an aggregate() result as a queryset 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. nobody mtredinnick   0 0 0 0 0 0
Powered by Datasette · Queries took 0.969ms