Re: How to use extra to count based on the value of a field?

2011-03-16 Thread Jason Culverhouse
On Mar 16, 2011, at 8:49 AM, Margie Roginski 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: > >

Re: How to use extra to count based on the value of a field?

2011-03-16 Thread Margie Roginski
Right again! I agree what you are saying works. I tried to take it a step further and OR together two querysets. I was then looking at the results of that OR, and it was not what I expected. One qs had been annotated with num_tasks_open, the other had been annotated with num_tasks_closed. I

Re: How to use extra to count based on the value of a field?

2011-03-16 Thread Tom Evans
On Wed, Mar 16, 2011 at 3:49 PM, Margie Roginski 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: > >

Re: How to use extra to count based on the value of a field?

2011-03-16 Thread Margie Roginski
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'))

Re: How to use extra to count based on the value of a field?

2011-03-15 Thread Margie Roginski
Ah, right - so obvious! I'm not sure why it didn't occur to me to filter first, then annotate. Thank you! On Mar 15, 2:43 am, Tom Evans wrote: > On Mon, Mar 14, 2011 at 8:57 PM, Margie Roginski > > wrote: > > class Queue(models.Model): > >  

Re: How to use extra to count based on the value of a field?

2011-03-15 Thread Tom Evans
On Mon, Mar 14, 2011 at 8:57 PM, Margie Roginski wrote: > class Queue(models.Model): >  # fields here, not relevant for this discussion > > class Task(models.Mode): >  queue = models.ForeignKey("Queue") >  status = models.IntegerField(choices=STATUS_CHOICES) > > I am

How to use extra to count based on the value of a field?

2011-03-14 Thread Margie Roginski
class Queue(models.Model): # fields here, not relevant for this discussion class Task(models.Mode): queue = models.ForeignKey("Queue") status = models.IntegerField(choices=STATUS_CHOICES) I am trying to create a Queue queryset that will annotate each Queue with the number of tasks whose