I have a Word model, it has many to many relation with Phrase model I want to get rid of this loop because it's not effective in terms of performance:
for w in words:
w.freq = w.phrases.count()
w.save()
I know I should use annotate and subquery, I have found this question Django: how to annotate queryset with count of filtered ForeignKey field? But don't really understand how I should do it in my case