<form action="{% url 'cart:cart_modificate' product.id %}" method="post">
{% csrf_token %}
<input type="hidden" name="product" value="{{product.id}}" />
<input type="hidden" name="increment" value="increment" />
<input type="submit" value="+" />
</form>
<form action="{% url 'cart:cart_modificate' product.id %}" method="post">
{% csrf_token %}
<input type="hidden" name="product" value="{{product.id}}" />
<input type="hidden" name="decrement" value="decrement" />
<input type="submit" value="-" />
</form>
def cart_modificate(request, product_id):
cart = Cart(request)
product = get_object_or_404(Product, id=product_id)
increment =
def cart_modificate(request, product_id):
if request.method =='POST':
increment = request.POST.get('increment')
... # для остальных полей по аналогии + добавить условие
<form action="{% url 'cart:cart_modificate' product.id %}" method="post">
{% csrf_token %}
<input type="submit" value="increment" />
<input type="submit" value="decrement" />
</form>
def cart_modificate(request, product_id):
if 'increment' in request.POST:
# do something
else:
# do something else
<form action="{% url 'cart:cart_modificate' %}" method="post">
{% csrf_token %}
<input type="hidden" name="id" value="{{product.id}}" />
<input class="cart_form" name="button" type="submit" value="+" />
<input class="cart_form" name="button" type="submit" value="-" />
</form>
def cart_modificate(request):
cart = Cart(request)
if request.method == 'POST':
product_id = request.POST['id']
button = request.POST['button']
product = get_object_or_404(Product, id=product_id)
if button == '+':
increment = button
decrement = None
else:
increment = None
decrement = button
cart.modificate(product, increment, decrement)
return redirect('cart:cart_detail')