From a8d2556834bdb75a3cff8464128956fc926288c9 Mon Sep 17 00:00:00 2001 From: Armin Ronacher Date: Mon, 24 Jan 2011 01:07:36 +0100 Subject: [PATCH] Improved documentation for sum --- jinja2/filters.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/jinja2/filters.py b/jinja2/filters.py index a51d25b..8cd8387 100644 --- a/jinja2/filters.py +++ b/jinja2/filters.py @@ -648,11 +648,19 @@ class _GroupTuple(tuple): @environmentfilter def do_sum(environment, iterable, attribute=None, start=0): - """Sums up an iterable. + """Returns the sum of a sequence of numbers plus the value of parameter + 'start' (which defaults to 0). When the sequence is empty it returns + start. + + It is also possible to sum up only certain attributes: + + .. sourcecode:: jinja + + Total: {{ items|sum(attribute='price') }} .. versionchanged:: 2.6 The `attribute` parameter was added to allow suming up over - attributes. + attributes. Also the `start` parameter was moved on to the right. """ if attribute is not None: iterable = imap(make_attrgetter(environment, attribute), iterable) -- 2.26.2