1# order_by count of foreign key relation
2from django.db.models import Count
3top_users = User.objects.filter(problem_user=False) \
4 .annotate(num_submissions=Count('submission')) \ # adds column "num_submissions" in "top_users"
5 .order_by('-num_submissions')
6