2👍
✅
Aggregation functions (like Count
) need to be used with annotate()
or aggregate()
. You can reference annotated fields from filter()
or Q()
:
Deals.objects.annotate(
participation_count=Count('deal_participation')
).filter(
nb_participants__gt=F('participation_count')
)
There’s an example in the Django docs
Source:stackexchange.com