[Answer]-Complex django queryset annotation with multiple subqueries

1👍

The SQL generated will probably be as tight as you can make it via the Django ORM. You can always validate that by printing out qs.query.sql_with_params() and seeing the generated SQL. If you need to, you can add indexes to the columns to speed up the count (postgres 9.2+).

Leave a comment