get the sum of an attribute django models

0

Good morning: I have a model Order and I need general a summary of all the orders that have been generated in the last 15 days, then I want to generate the total of all the orders and I do not know how to do it. for the moment I have this:

pedidos = Pedido.objects.filter(fecha_pedido__range = [año + '-' + mes +'-'+ ini, anno + '-' + mes +'-' + fin])
rows=pedidos.order_by('numero_cuenta').values_list('usuario','nombre_completo','dni','banco','numero_cuenta','tipo_cuenta','precio_producto','comision','impuesto','total')

This brings me all the orders but I want to make a kind of distinct and add a calculated field that is the sum of the total field of all orders of each user

    
asked by F Delgado 18.01.2018 в 09:48
source

1 answer

2

You can do it in the following way:

pedidos = Pedido.objects.filter(fecha_pedido__range = [año + '-' + mes +'-'+ ini, anno + '-' + mes +'-' + fin]).aggregate(Sum('campo a sumar'))

I hope you serve

    
answered by 18.01.2018 / 15:48
source