📅  最后修改于: 2022-03-11 14:47:02.647000             🧑  作者: Mango
# order_by count of foreign key relation
from django.db.models import Count
top_users = User.objects.filter(problem_user=False) \
.annotate(num_submissions=Count('submission')) \ # adds column "num_submissions" in "top_users"
.order_by('-num_submissions')