>
> 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.
Hi Jonas,
your gut feeling was correct - it's not a very good idea, although
it might work for a small site. You might want to take a look at
database aggregation in Django:
http://docs.djangoproject.com/en/1.2/topics/db/aggregation/
Cheers
Jirka
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
No comments:
Post a Comment