我目前有一个Restaurant
模型,其中有关联的模型Review
和Comment
。用户可以评论和评论餐厅。你知道吗
我试图在Django中创建权重逻辑,其中我显示了权重最大的前三家餐厅。你知道吗
当前的逻辑如下所示:
restaurants = Restaurant.objects.all()
top_3 = restaurants.annotate(weight=(Count('review')) + F('views') + (Count('comment'))).order_by('-weight')
我该如何更新这个逻辑,以便只有过去7天的评论和评论被纳入权重?你知道吗
编辑
Review和Comment模型都有一个用于跟踪对象创建时间的字段:
pub_date = models.DateTimeField(default=timezone.now, blank=True)
我希望这将有助于:
review__isnull=True
和comment__isnull=True
不过滤掉没有reviews
和comments
的restaurants
。如果你不关心这些restaurants
,你可以使用这个过滤器:文件
相关问题 更多 >
编程相关推荐