def buynow(request, prid): current_user = request.user Cart.objects.filter(user_id=current_user.id).delete() data = Cart() data.user_id = current_user.id data.product_id = prid data.qty = 1 data.save() return HttpResponseRedirect('/cart')
def addtocart(request, prid): url = request.META.get('HTTP_REFERER') current_user = request.user check_product = Cart.objects.filter(user_id=current_user.id, product_id=prid) if check_product: control = 1 else: control = 0 if control == 1: data = Cart.objects.get(user_id=current_user.id, product_id=prid) data.qty = data.qty + 1 data.save() else: data = Cart() data.user_id = current_user.id data.product_id = prid data.qty = 1 data.save() messages.success(request, data.product.product_name + " added to the Cart.") return HttpResponseRedirect(url)