On Wed, Mar 16, 2011 at 3:49 PM, Margie Roginski
<[email protected]> wrote:
> Hmmm ... so I just got back to trying this and I actually don't think
> the annotate call as suggested does what I am looking for. Say I want
> to annotate queues with the number of closed tasks. This call:
>
> Queue.objects.filter(task__status=Task.STATUS_CLOSED).annotate(num_tasks=Count('task'))
>
> finds all queues that have tasks that are closed, but then it
> annotates the queue with the total number of tasks that point to the
> queue, not just the number of closed tasks that point to the queue.
No, you are incorrect. An example with similar models:
>>> qs = TVSeries.objects.filter(name='South
>>> Park').filter(tvepisode__title__contains='hero').annotate(num_episodes_with_hero_in_title=Count('tvepisode'))
>>> qs[0].num_episodes_with_hero_in_title
1
>>> qs2 = TVSeries.objects.filter(name='South
>>> Park').annotate(num_episodes=Count('tvepisode'))
>>> qs2[0].num_episodes
202
As you can see, the annotate is clearly correctly affected by the
earlier filter.
Cheers
Tom
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en.