On 1/13/07, Picio <[EMAIL PROTECTED]> wrote:

Hello,
in my custom view, when I retrieve a query set, I need to add (i mean
do the sum) of all the values in a column. Is there a built in
django-way to do it, instead to write python code myself?
In the db_api I saw order_by but I cant see something related to SUM.

I know there is .extra method to execute SQL statement but it would be
better for me if there is any django built in method to do it.

well the easiest way to do that is

qset.extra( select={ 'sum' : "SUM( column_name )" } )

it will just add an extra field to the result containing the sum.
There is no "special" way to treat this, nor to specify group by, if
you need that, you have to drop back to raw sql:

http://www.djangoproject.com/documentation/model_api/#executing-custom-sql


I hope It's not a dummy question!
Thanks a lot.
Picio

>



--
Honza Kr l
E-Mail: [EMAIL PROTECTED]
ICQ#:   107471613
Phone:  +420 606 678585

--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to