0

我列出了我的帐户交易的借方和贷方。现在我想在最后一列中运行总计,借方减去贷方加上先前到达的金额作为运行总计(如您所知)。谢谢你的支持。

我的观点:

 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]
4

1 回答 1

0

感谢 E 保罗。我修改后的观点是

 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>
于 2021-05-21T07:37:01.770 回答