Django showing the result of a query with decimal()

1.7k views Asked by At

Hello I have a question about the result of a query.

suma = Contrato.objects.aggregate(Sum('lote__Costo'))

The result is the sum of all the records in a column of the database.

What I can not understand exactly is the way in which I get the result of the query which is shown as follows

{'lote__Costo__sum': Decimal('142000.00')}

Is equal in the shell as in the template I wonder if there is a way to display only the result of the query.

Thanks.

1

There are 1 answers

0
Bijoy On BEST ANSWER

To get the value you can do

suma = Contrato.objects.aggregate(Sum('lote__Costo'))
decimal_val = float(suma['lote__Costo__sum'])

and then pass the value(decimal_val) to template