Skip to content

Instantly share code, notes, and snippets.

@spenthil
Created May 16, 2012 21:45
Show Gist options
  • Save spenthil/2714212 to your computer and use it in GitHub Desktop.
Save spenthil/2714212 to your computer and use it in GitHub Desktop.
filtering on empty GenericRelation
In [24]: InsuranceClaim.objects.annotate(num_invoiceitems=Count('invoiceitems')).filter(num_invoiceitems__gt=0).count()
Out[24]: 29319
In [25]: InsuranceClaim.objects.annotate(num_invoiceitems=Count('invoiceitems')).filter(num_invoiceitems__eq=0).count()
Out[25]: 9826
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment