Rocky Holms Rocky Holms - 1 month ago 4
Python Question

Top 7 most common tags Taggit

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


How would I edit this to only view the top 7 tags. This is a function from taggit and I would only like to see only 7. thanks.

Answer

How about most_common()[:7]? docs.djangoproject.com/en/1.10/topics/db/queries/… – ozgur

This is the correct asnwer, thanks ozgur