Very simple... I am using Django 1.4.1, and need to order a queryset by the inverse of the number of comments on it. I am using the Django comment framework, and have attempted to use the .annotate(comment_count = Count('comment') structure recommended in other answers... I get 'comment' doesn't resolve to a field error.
I've also tried the 0.3.1 version of django-generic-aggregate, which throws a database error, so that's out.
Photo.objects.filter(galleries=gallery).annotate(comment_count=Count('comments')).order_by('-comment_count')[(page-1)*RESULTS_PER_PAGE:page*RESULTS_PER_PAGE]
Any suggestions?