There might be a better way, but something like this should work.

In your view, build a list...

transaction_list = []
balance = 0
for tran in Transaction.objects.order_by('date'):
    balance = balance + tran.debit
    balance = balance - tran.credit
    transaction_list.append({'transaction':tran,'balance':balance})

Then in your view, you loop through the transaction list.
row.transaction will be a model instance

{% for row in transaction_list %}
   {{ row.transaction.description }}
   {{ row.transaction.debit }}
   {{ row.transaction.credit }}
   {{ row.balance }}
{% endfor %}

On Feb 18, 10:52 am, Marcelo Barbero <barberomarc...@gmail.com> wrote:
> I have a model with accounting records, in which the last two columns
> are "Debt" and "Credit".
>
> I would like to do a report that is something like the following:
>
> Description               Debt        Credit      Balance
> Movement 1            100.00        0.00         100.00
> Movement 2                0.00      20.00           80.00
>
> Etc.
>
> I can do this with a database view and working with the records
> one-by-one in the Django view function, but I was wandering if there
> is  a better approach, because I'm doing this using raw SQL and then I
> lose lots of Django model functionality.
>
> Marcelo

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to