I have some products listed which can be in a cart, this cart is stored in a session variable dictionary for which the key is the product id and the value is some information about the quantity and stuff. I want to add the option to view (on the products page) how many of that product are in your cart.
I know I can access session variables in a django template like this:
{{ request.session.cart.2323.quantity }}
Problem is, the key (2323 in this case) is a variable which depends on a for
loop:
{% for prod in products %}
<p>{{ request.session.cart[prod.name].quantity }}</p>
{% endfor %}
But implementing it like that unfortunately is not possible. Is there any way in which this would be possible or would I have to change the way my cart works?