First of all I know of the django-taggit application. But I'm new to django and 
I thought this would be a good way of getting to know this great framework a 
little bit better.
That lined out, I have a Post and a Tag model. Each Tag.name property of the 
tag model is unique.

I'm trying to figure out which Tags are used most.

I do this by the following code:

from homepage.models.blog import Post, Tag

indexed_tags = {}

tags = Tag.objects.all()

for t in tags:
    indexed_tags[t] = Post.objects.filter(tags__name=t).count()

Next I would sort indexed_tags and I have a dictionary of which tags are used 
the most.

I'm wondering if this is a good idea ? Since if I have 1000 tags this would 
require 1000 queries just for one simple tag cloud.
Is there a better way of solving this without adding an extra count field to 
the Tag model.




Regards,

Jonas Geiregat
jo...@geiregat.org




-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to