2👍
✅
Team.objects.annotate(c=Count('all_players')).filter(c__gt=12')
What this would do is:
-
In each record/row in the
Team
model/table it will append/annotate a new value. Thec
one. You can name it whatever you like. Thisc
will be the number ofplayer
s thisrow
/record
is associated with. -
Then, since the
c
value is annotated in all rows, it will filter those and get all rows which havec
greater that 12 (player
s).
Source:stackexchange.com