So this is my template where I have a table with products. Each product has a default "in_cart" value of False. So each row has a submit button "add to cart". I would like to change on click the boolean value to true so it appears in /cart. this is the table:
{% load staticfiles %}
<table>
<tr>
<th>List of car parts available:</th>
</tr>
<tr>
<th>Name</th>
<th>Price</th>
</tr>
{% for product in products_list %}
<tr>
<td>{{ product.name }}</td>
<td>${{ product.price }}</td>
<td>{% if not product.in_cart %}
<form action="{% url 'cart' %}" method="post">
{% csrf_token %}
<input type="submit" id="buttonId" value="Add to cart">
</form>
{% else %}
{{ print }}
{% endif %}
</td>
</tr>
{% endfor %}
</table>
I created a file in myapp/static/submit.js
$('#buttonId').click(function() {
$.ajax({
url: 'cart/',
method: 'POST',
data: {
name: product.in_cart,
click: true
}
success: function (data) {
}
});
});
Don't really know how to go from there.