bklukaczewski
5/9/2016 - 12:18 PM

annotate reverse foreign key count

annotate reverse foreign key count

# returns objects which have at least 1 operationalplan
Product.objects.annotate(operational_plans_no=Count('operationalplan')).filter(operational_plans_no__gt=0)