我创建列表的代码是:
choices = []
for bet in Bet.objects.all():
#...
#Here is code that skip loop if bet.choice exist in choices[]
#...
temp = {
'choice':bet.choice,
'amount':bet.sum,
'count':bets.filter(choice=bet.choice).count()}
choices.append(temp)
choices.sort(key=attrgetter('choice'), reverse=True)
choices.sort(key=attrgetter('amount'), reverse=True)
choices.sort(key=attrgetter('count'), reverse=True)
Run Code Online (Sandbox Code Playgroud)
我必须按列表排序因为模型orderby()不能按count()排序,可以吗?