Improved API for aggregating using Subquery in Django. Provides SubqueryAggregate, SubqueryCount, SubquerySum, etc. Current version 0.7.0, supports Django 1.11 to 3.0+. Maintenance frequency: irregular, last release 2020.
pip install django-sql-utilsVerified import paths — ran on the pinned version, not inferred.
Replace 'myapp.models' with your actual app/models. The SubqueryAggregate family works like Django's aggregates but generates subqueries.
Use SubqueryCount('author') instead of SubqueryCount('author_id') or SubqueryCount('author__id').Test thoroughly with your Django version. Consider switching to Django's built-in Subquery() and annotate() if using Django 3.0+.
Migrate to Django's annotate() with Subquery() and OuterRef().
Upgrade to 0.7.0 or ensure related_name and related_query_name match.
No dependency data recorded yet.