17. Displaying cart
Next, we will ensure that the ordered items are displayed within the cart page.
def cart(request):
if request.user.is_authenticated:
client = request.user.client
order, created = Order.objects.get_or_create(client=client, finished=False)
items_ordered = OrderedItem.objects.filter(order = order)
context = {"order" : order, "items_ordered" : items_ordered}
return render(request, 'cart.html', context) {% extends 'base.html' %}
{% load static %}
{% block body %}
<h3>Cart</h3>
<h4>Order ID: {{ order.id }}</h4>
{% for item in items_ordered %}
<p>
<img src="{{ item.itemstock.product.image.url }}" width = "60" height = "80">
Product: {{ item.itemstock.product.name }}; Color: {{ item.itemstock.color.name }}; Size: {{ item.itemstock.size }}; Quantity: {{ item.quantity}}
</p>
{% endfor %}
<a href = "{% url 'checkout' %}">Checkout</a>
{% endblock %}
Last updated