Re: SUM on a model

2008-04-27 Thread dimrub
In addition to the above, you can have a field in your model, that will contain that sum, and update it in your save(). It may not be as beneficial with sum() as it is with some other functions that work on multiple rows. 陈亮 wrote: > Hi there, > I've googled a lot on how to get the sum of a i

Re: SUM on a model

2008-04-27 Thread James Bennett
On Sun, Apr 27, 2008 at 8:47 AM, Darryl Ross <[EMAIL PROTECTED]> wrote: > I use: > >total = sum([obj.amount for obj in Model.objects.all()]) As of the merge of qsrf, this will also work: total = sum(Model.objects.values_list('amount', flat=True)) Plus there's the SoC project which will

Re: SUM on a model

2008-04-27 Thread Darryl Ross
陈亮 wrote: Hi there, I've googled a lot on how to get the sum of a integer field for all the objects of a model. There are some solutions. But none of them looks like a standard way to do so. Does django have this feature? I use: total = sum([obj.amount for obj in Model.objects.all()])