我想为每个日期返回 3 个结果,并按日期和每个查询的单独“评级”列对结果进行排序
例如,我的查询将返回如下内容:
Event on Dec 1st rated 36
Event on Dec 1st rated 29
Event on Dec 1st rated 12
Event on Dec 2nd rated 45
Event on Dec 2nd rated 12
Event on Dec 2nd rated 9
Event on Dec 3rd rated 118
Event on Dec 3rd rated 15
Event on Dec 3rd rated 13
我知道这应该可以使用具有以下内容的原始 sql:SQL group - limit
但我想知道是否有一种方法可以在 Django ORM 中通过单个查询执行此操作,或者如果我确实需要转换为原始 SQL 查询,至少有一种方法可以使其尽可能轻松。
编辑: 模型很简单。相关领域是:
class Event(models.Model):
title = models.CharField(max_length=120)
day = models.DateField()
score = models.SmallIntegerField()