Hi all,

I've just upgraded to 1.1 (congrats everybody!), and want to put the
aggregation/annotation features to use.  but it doesn't seem to be a
way to annotate the records with counts of different subsets of
related records.

my problem:  i have  'Order' and 'Item' models, and the items can be
on several states or processing:

class Order (models.Model):
       order_no = models.Integerfield()
       date = models.DateTimeField()
       client = models.ForeignKey (Client)

class Item (models.Model):
       order = models.ForeignKey (Order)
       description = models.CharField (max_length=50)
       price = models.DecimalField (max_digits=7, decimal_places=2)
       quantity = models.IntegerField()
       status = models.SmallIntegerField()

and I want to show a list of all the orders, with columns showing how
many items are on each state:

| order  | client       | not yet | processing | ready |
--------------------------------------------------------
| 000001 | Jon Doe      |    5    |     4      |   0   |
| 000002 | Jane Smith   |    2    |     7      |   3   |
--------------------------------------------------------

so far, i only found how to add a column with the total number of items:

Order.objects.annotate(Count('item'))

but i can't count subsets of items.  Is there any way to do that in
the DB, or I have to do it in Python?

--
Javier

--~--~---------~--~----~------------~-------~--~----~
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