How can I count related objects in Django (less than N requests, where N is the number of objects).
To clarify, let's say I have tables A and B. Each B is related to the accuracy of one A. The approach I tried:
A.objects.select_related().filter(attr=val) A[i].B_set.count()
Of course, for each A [i] I want to know the number of objects B. Django makes one request.
So the question is, is there a way to optimize it?
source share