📜  django 按外键计数排序 - Python 代码示例

📅  最后修改于: 2022-03-11 14:47:02.647000             🧑  作者: Mango

代码示例1
# 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')