1 回答

TA貢獻(xiàn)1111條經(jīng)驗(yàn) 獲得超0個(gè)贊
首先刪除你的@property balance功能
然后在views.py
def index(request):
all_transactions = Transaction.objects.annotate(cumsum=Func(Sum('amount'),template='%(expressions)s OVER (ORDER BY %(order_by)s)',order_by="id"))
context = {
"transactions": all_transactions
}
return render(request,'pages/index.html', context)
然后在你的index.html
{% for each_transaction in transactions %}
<tr>
<td>{{each_transaction.transaction_date}}</td>
<td>{{each_transaction.account_nickname}}</td>
<td>{{each_transaction.amount}}</td>
<td>{{each_transaction.cumsum}}</td>
</tr>
{% endfor %}
添加回答
舉報(bào)