Here\'s my database query:
results = Attachments.objects.filter(currency=\'current\').annotate(num_attachments=Count(\'article_id\')).order_by(\"num_attachme
I have find another way, how to overcome this - by using a subquery:
distinct_articles = Attachments.objects.distinct('article_id')
results = Attachments.objects.filter(currency='current').annotate(num_attachments=Count('article_id')).order_by("num_attachments").filter(id__in=distinct_articles)
This get actually evaluated as one database query in Django.