Код: Выделить всё
def plus_cart(request):
if request.method == "GET":
pk = request.GET.get('prod_id')
c = Cart.objects.get(pk=pk, user=request.user)
c.quantity+=1
c.save(update_fields=['quantity'])
user = request.user
cart = Cart.objects.filter(user=user)
amount = 0
for p in cart:
value = p.quantity * p.product.dp
amount = amount + value
totalamount = amount + 40
data={
'quantity':c.quantity,
'amount':amount,
'totalamount':totalamount,
}
return JsonResponse(data)
path('pluscart/',views.plus_cart),
в static папка myscript.js имеет следующий код:
Код: Выделить всё
$('.plus-cart').click(function(){
var id=$(this).attr("pid").toString();
var eml=this.parentNode.children[2]
console.log("pid= ", id)
$.ajax({
type:"GET",
url:"/pluscart",
data:{
prod_id:id
},
success:function(data){
console.log("data= ", data);
eml.innerText=data.quantity
document.getElementById("amount").innerText=data.amount
document.getElementById("totalamount").innerText=data.totalamount
}
})
})
Подробнее здесь: https://stackoverflow.com/questions/790 ... oes-not-ex
Мобильная версия