Skip to content

Instantly share code, notes, and snippets.

@tim-schilling
Created September 8, 2023 18:24
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tim-schilling/f5d90279754e288e0e4e2df9e2a2811b to your computer and use it in GitHub Desktop.
Save tim-schilling/f5d90279754e288e0e4e2df9e2a2811b to your computer and use it in GitHub Desktop.
Subquery Count
from django.db.models import IntegerField, Subquery
class SubqueryCount(Subquery):
template = "(SELECT COUNT(*) FROM (%(subquery)s) _count)"
output_field = IntegerField()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment