3 ms·
Serious question: is the famous bug of correctly annotating multiple counts fixed now?
by myf01d 9y ago
Serious question: is the famous bug of correctly annotating multiple counts fixed now?
- lamby 9y agoHuh, I'm a big Django user but not heard of this. Link? :)
- brianwawok 9y agoMe either I am guessing it is one of the points where the ORM breaks down.. which the answer is "use rawSQL"
- orf 9y agoNope that's still a limitation and a tricky one to solve, and I agree it's really really annoying. I added support for filtered aggregates[1] in this release, if you're annotating multiple counts this might be useful for you. 1. https://docs.djangoproject.com/en/2.0/ref/models/conditional-expressions/#conditional-aggregation https://docs.djangoproject.com/en/2.0/ref/models/conditional...
- lozenge 9y agoI'm guessing you're referring to this - https://stackoverflow.com/questions/6795202/django-count-in-multiple-annotations https://stackoverflow.com/questions/6795202/django-count-in-... Another solution not mentioned in the link is the `Subquery()` expressions added in Django 1.11. A lot of databases will optimise those just as well as the `SELECT ..., COUNT() FROM ..JOIN..` that you would write by hand.