我有以下型号
class Dishes(models.Model):
name = models.CharField(max_length=40, unique=True)
date_added = models.DateTimeField(auto_now_add=True)
#increment/decrement with upvote added or removed
count_votes = models.IntegerField(blank=True, null=True, default=0)
class Upvotes(models.Model):
dish = models.ForeignKey(Dishes)
user = models.ForeignKey(User)
date_added = models.DateTimeField(auto_now_add=True)
我有 3 种菜肴,前 2 种是按 date_add 和 count_votes,这很容易用 discs.order_by('-count_votes') 和 disc.order_by('-date_added') 来实现,第三种是“趋势排序” “我基本上想成为一种随着时间的推移将菜肴排名为赞成票的函数,知道我该怎么做吗?