Question

I'm trying to get an ordered list of the most-used tags on my site. The API docs for django taggit reference a most_common() method, but I can't seem to make it work. Docs say:

"Returns a QuerySet of all tags, annotated with the number of times they appear, available as the num_times attribute on each tag."

But they don't show a working example. Assuming that an "Item" model has a working "tags" field, does this mean you should be able to do something like:

Item.objects.all.tags.most_common()

I've tried variations of this but can't seem to get an ordered list of most-used tags. What's the magic incantation expected here?

Was it helpful?

Solution

I believe it should be without the objects.all:

tags = Item.tags.most_common()
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top