Here are my models:

class Entry(models.Model):
        name = models.CharField(max_length=200, unique=True)
        date_published = models.DateTimeField()
        is_published = models.BooleanField(default=False)

class Comment(models.Model):
        entry = models.ForeignKey('Entry')
        name = models.CharField(max_length=100)
        approved_choices = (('N', 'No'), ('Y', 'Yes'), ('M', 'Needs
Moderation'),)
        approved = models.CharField(max_length=1,
choices=approved_choices, default='N')


I have this query in my view:

latest_entry_list = Entry.objects
        .annotate(comments=Count('comment'))
        .filter(is_published=True)
        .order_by('-date_published')
        [:15]

It simply returns 15 "is_published" Entry's ordered by
"date_published" and a count of all of the Entry's Comments. It works
perfectly.

I'd now like to only return the count of comments where approved = 'Y'
and I have no idea how to go about this as adding
"comment__approved='Y'" to the filter limits the result to only
Entry's that have approved comments. I'd like all the Entry's and just
a count of the approved comments.

Is this possible?
--~--~---------~--~----~------------~-------~--~----~
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