I have created a function to get some date from database, make some calculations and show it in HTML files. However I could not to get just values from views.
def list_pay(request):
item = Pay.objects.all()
# Quantidades
q_total = Pay.objects.all().count
q_open = Pay.objects.filter(status=0).count
q_paied = Pay.objects.filter(status=1).count
# Soma dos valores
v_total = Pay.objects.aggregate(Sum('value'))
v_open = Pay.objects.filter(status=0).aggregate(Sum('value'))
v_paied = Pay.objects.filter(status=1).aggregate(Sum('value'))
data = {
'item':item,
'v_total':v_total,
'v_open':v_open,
'v_paied':v_paied,
'q_total':q_total,
'q_open':q_open,
'q_paied':q_paied
}
return render(request, 'pay/list_pay.html', data)
Lista de pagamentos
<div class="col m-3 p-3">
<label>Total de boletos</label>
<h1 class="text-primary"> {{ q_total }}</h1>
<h1 class="text-primary"> {{ v_total }}</h1>
</div>
<div class="col m-3 p-3">
<span>Quantidade de boletos</span>
<h1 class="text-success">{{ q_paied }}</h1>
<h1 class="text-success">{{ v_paied }}</h1>
</div>
<div class="col m-3 p-3">
<span>Quantidade de boletos</span>
<h1 class="text-danger">{{ q_open }}</h1>
<h1 class="text-danger">{{ v_open }}</h1>
</div>
The current value loaded = {‘value__sum’: 1831}. The expected output = 1831
I alredy try .values() and transform the dict in a list and other format.
New contributor
Ricardo Ferrari Pasqualino is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.