[Answered ]-Working with annotate django

2👍

Team.objects.annotate(c=Count('all_players')).filter(c__gt=12')

What this would do is:

  1. In each record/row in the Team model/table it will append/annotate a new value. The c one. You can name it whatever you like. This c will be the number of players this row/record is associated with.

  2. Then, since the c value is annotated in all rows, it will filter those and get all rows which have c greater that 12 (players).

👤nik_m

Leave a comment