最常见的7个标签Taggit

时间:2016-09-12 04:30:12

标签: python django django-views

def most_common(self):
    return self.get_queryset().annotate(
        num_times=models.Count(self.through.tag_relname())
        ).order_by('-num_times')

我如何编辑它以仅查看前7个标签。这是taggit的一个功能,我只想看到7.谢谢。

1 个答案:

答案 0 :(得分:0)

most_common()[:7]怎么样?

YourModel.tags.most_common()[:7]

docs.djangoproject.com/en/1.10/topics/db/queries/... - ozgur

这是正确的asnwer,谢谢ozgur