@login_required
def add(request, product_id):
    product = get_object_or_404(Product, pk=product_id)
    cart_items = Cart.objects.filter(user=request.user, product=product)
    if cart_items:
        cart = cart_items.first()
    else:
        cart = Cart(user=request.user, product=product)
    cart.quantity += 1
    cart.save()
    return HttpResponseRedirect(request.META.get('HTTP_REFERER'))
@login_required
def add(request, product_id):
    product = get_object_or_404(Product, pk=product_id)
    cart_items = Cart.objects.filter(user=request.user, product=product)
    if cart_items:
        cart = cart_items.first()
    else:
        cart = Cart(user=request.user, product=product)
    cart.quantity += 1
    cart.save()
    return HttpResponseRedirect(request.META.get('HTTP_REFERER'))