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
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
陈亮 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()])
3 matches
Mail list logo