我有从 Entry
到 Vote
的外国密钥, 我想排序在某个日期之前创建的 Vote
。 我如何才能以良好的方式做到这一点? 通常我会做 :
entries = Entry.objects.annotate(
num_votes = Count( votes )).order_by( -num_votes )
page = request.GET.get( page )
paginator = Paginator(entries, 12)
try:
entries = paginator.page(page)
except PageNotAnInteger:
entries = paginator.page(1)
except EmptyPage:
entries = paginator.page(paginator.num_pages)
如何分类才能只算出在某个日期之前产生的选票? 我唯一的选择就是查询DB,然后对每件事进行反复处理吗?