Passing several attributes in django

0

My question is the following. I am starting my studies in django and encounter a problem. I have a function in my view with the following excerpt

def saldo_total(request):
    receitas = Receitas.objects.aggregate(Sum('valor'))
    total_receitas = receitas['valor__sum']
    despesas = Despesas.objects.aggregate(Sum('valor'))
    total_despesas = despesas['valor__sum']

    receitas = receitas['valor__sum']
    despesas = despesas['valor__sum']

    total = total_receitas - total_despesas

    return render(request, 'financas/saldo_total.html', {'total': total}, {'receitas': receitas}, {'despesas': despesas})

It does a db search by adding the sum of the revenue and expenses, and also below, subtract one by the other to inform the available balance of the user.

However, rendering only allows me to throw an attribute to return and I would like all three to be returned.

Is there any way to do this in django?

    
asked by anonymous 05.05.2018 / 22:58

1 answer

0

Yes. What you put in render is a dictionary, and dictionaries can contain more than one key / value pair.

What you want is equivalent to the following:

return render(request, 'financas/saldo_total.html', {'total': total, 'receitas': receitas, 'despesas': despesas})

Or, in a more organized way:

dados = {'total': total, 
         'receitas': receitas,
         'despesas': despesas }
return render(request, 'financas/saldo_total.html', dados)
    
05.05.2018 / 23:40