'django ajax project- basket - collecting values in array
in my Django store I have a basket which in views.py has the class:
class BasketAddView(View):
def post(self, request, *args, **kwargs):
basket = Basket(request)
product_id = str(request.POST.get('productid'))
product_size = str(request.POST.get('productsize'))
product_qty = str(request.POST.get('productqty'))
product = get_object_or_404(Product, id=product_id) #it was id and should be p
basket_size_table = []
basket_size_table.append(product_size)
basket.add(product=product, size=product_size, qty = product_qty)
basketqty=basket.__len__()
response = JsonResponse({'size': basket_size_table,'product' : product_id, 'qty': basketqty, })
return response
web inspector in output in console show that I have only last size in array:
[] 1
but I would like to have a collections of sizes in one array. Product_size is a single element, in html it is a select field with different values. I wish I could add these individual values to the list of product with the same id but different sizes, example : product:"6" qty: 2 size: ['8/ϕ15mm/US5','7/ϕ14mm/US6']
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|