Hi there!

I'm trying to see what's the best approach in my scenario.
The problem is how to make a list display different sums and 
calculations based on it's child objects.


My scenario could be the following:
Two models: Project and Task
One Project has many Task.
Task has a boolean "open" field (open,closed) and a due_date.

I want to retrieve a list of projects that includes the total number of 
tasks (that one is easy ;), number of open tasks and number of tasks 
with due_date today.


First of all, I understand that this would not be possible with the new 
Aggregation / Annotation functionality, right? (Maybe I'm mistaken)
I cannot do something like:
projects = Project.objects.all(),annotate(total=Count('task'), 
open_tasks=Count('task__open=True'), 
due_today=Count('task__due_date=datetime.today()')

Second, if not, what would be the best way to approach this scenario?

My first idea is to create functions on my Project model that gives me 
this info. (This doesn't scale very well ;)
The next thing would be to create a Custom Manager that adds this info 
via some custom SQL. (I really don't feel comfortable with this approach 
since I seem to be completely overriding django's ORM)
The last option would be to add some extra SQL to my QuerySet through 
the extra parameter.



Any insight would be appreciated.


Regards, Stefan

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