It works very well.
from collections import defaultdict
count = defaultdict( int )
for doc in XML_Table.objects.filter(suid='2'):
count[doc.pid] += 1
This is not SQL. This is often faster than SQL because it does not impose sorting on a large table or the result of a join.
source
share