Filters take two arguments, the value that you pass to the filter and an argument that you can use to control its behavior. You could use the last argument to tell sum_monto to sum the positive values or the negative values.

This is a quick untested filter implementation off the top of my head:

Thanks, i wouldn't have think of the the filter, i need to do it in the template because it's an arbitrary number of Documentos
–
armongeSep 20 '10 at 18:07

How does an arbitrary number of documents prevent you from calculating the sums in the view?
–
ArlaharenSep 20 '10 at 19:47

I don't know...maybe is because i'm a noob with django and more used to the PHP way of things,
–
armongeSep 20 '10 at 20:21

1

I mean, in php I would have a temporary variable inside the loop, here i would do my calculations and finally echo....but in the view? here? i just don't know how to
–
armongeSep 20 '10 at 20:23

OK. Perhaps you are there is some confusion on the Django term view? In Django, the view is the piece of code that handles your request and invokes the template. In your case you are probably performing some database query to get your documents. In that same place you could calculate your sums and send them to the template the same way you send your documents.
–
ArlaharenSep 21 '10 at 6:38