我列出了账户交易的借方和贷方。现在我想把最后一列的总额除以借方减去贷方,再加上之前到达的金额,作为运行总额(正如你所知(。感谢您的支持。
我的观点:
def listaccounttrans(request):
alltrans = FinTransDetail.objects.all()
context = {'alltrans': alltrans}
return render(request, 'waccounts/list_account_trans.html', context)
我的html:
{{% extends 'wstore_base_generic.html' %}}
{% block content %}
<h3>Table</h3>
<div>
<table id="customers" >
<thead>
<tr>
<td>AcctCode</td>
<td>TransNo</td>
<td>TransDate</td>
<td>AcctDetail</td>
<td>Debit</td>
<td>Credit</td>
<td>Balance</td>
</tr>
</thead>
<tbody>
{% for acct in alltrans%}
<tr>
<td>{{ acct.fd_acct }}</td>
<td>{{ acct.fd_no}}</td>
<td>{{ acct.fd_no.fh_dt}}</td>
<td>{{ acct.fd_no.fh_detail }}</td>
<td>{{ acct.fd_debit }}</td>
<td>{{ acct.fd_credit }}</td>
<td>{{ acct.fd_no}}</td> # needs running total here#
</tr>
{% endfor %}
</tbody>
</table>
</div>
{% endblock %}
我的模板现在显示:
AcctCode TransNo TransDate AcctDetail Debit Credit Balance
1101 94 May 18, 2021 Detail 11.00 0.00 94 (needs to be replaced with
1101 94 May 18, 2021 Detail 0.00 11.00 94 running balance)
[total balance]
感谢E Paul。我修改后的观点是
def listaccounttrans(request):
alltrans = FinTransDetail.objects.all()
openbal=0
for item in alltrans:
openbal=openbal+(item.fd_debit-item.fd_credit)
item.balance=openbal
context = {'alltrans': alltrans}
return render(request, 'waccounts/list_account_trans.html', context)
现在你可以参考模板:
<td>{{ acct.balance }}</td>