I think you can not do that with only one query using annotate.

You could do it manually in python using the code above including the
additional filter on comment_approved and merge all (entry, number)
pairs with Entry.objects.all() using 0 for entries which are not
listed in your first query. Since you won't display thousands of
entries at the same time, this should not be a problem.

You could also use extra to insert a subquery into your sql statement.
See.:
http://docs.djangoproject.com/en/dev/ref/models/querysets/

For example: (just the idea)
entries = Entry.objects.all().extra(select={"approved_comment_count":
"SELECT Count(*) FROM Comment WHERE Comment.Entry_id = Entry.id AND
Comment.is_published = True AND Comment.approved = 'Y'"})

Cheers,
Thomas
--~--~---------~--~----~------------~-------~--~----~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to