最佳答案
我使用一个事务模型来跟踪通过系统的所有事件
class Transaction(models.Model):
actor = models.ForeignKey(User, related_name="actor")
acted = models.ForeignKey(User, related_name="acted", null=True, blank=True)
action_id = models.IntegerField()
......
我怎样才能得到我系统里的前五名演员?
在 sql 中,它基本上是
SELECT actor, COUNT(*) as total
FROM Transaction
GROUP BY actor
ORDER BY total DESC