Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

most_common with django-taggit

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?

like image 371
shacker Avatar asked Jan 30 '26 13:01

shacker


1 Answers

I believe it should be without the objects.all:

tags = Item.tags.most_common()
like image 79
Mariusz Jamro Avatar answered Feb 01 '26 17:02

Mariusz Jamro



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!