0

I have two arrays sent with ajax from template. One array contains the product id and the second is the quantity. The problem is when I get the price of product per piece from database I must to multiply with the quantity.

How can I do price_product[ a, b, c,d] * quantity[30,50,40,70] => a*30, b*50 ....??

This is my current code

def price(request):
product = request.POST.getlist('product[]')  #exemple product id ['1','3','5']
quantity = request.POST.getlist('quantity[]') #exemple quantity['30','50','6']
price_product = list(set(ListProduct.objects.filter(id__in=product).values_list('price_buc', flat=True)))
context = {
'data': price_product
}
return JsonResponse(context)
Florin
  • 292
  • 2
  • 13

1 Answers1

0

This isn't really a django problem since you are actually using Python lists to multiply element-wise. I wont flag this as a duplicate, but really you should be doing this... https://stackoverflow.com/a/10271504/4954874

Oh Great One
  • 374
  • 2
  • 17