I use Django-Tagging and I don’t need a cloud, I just need a limited list of the most popular tags used on my blogs.
Using the following:
[(tag.name, int(tag.count)) for tag in Tag.objects.usage_for_model(Post, counts=True)]
It returns an array (note that I use Lorem Ipsum during development):
[(u'deposit', 5), (u'escorol', 1), (u'gratuitous', 8), (u'marquee', 2)]
But then, to order and restrict it, I have to do the following:
sorted([(tag.name, int(tag.count)) for tag in Tag.objects.usage_for_model(Post, counts=True)], key=lambda k:k[1], reverse=True)[:10]
Is there an easier way to do this? I feel it should be.
source
share