So basically in my store, every item has a specific weight and once the customer adds whatever they want and go to checkout, they can see every single order of theirs along with the name information and weight. I want to also add the total weight of all the items together. Currently, it displays only the weight of each particular item.
For example
This is my views.py
def checkout(request):
try:
current_order = Order.objects.filter(owner=1).get(status="pre-place")
except Order.DoesNotExist:
return HttpResponse("Your current order is empty<br><a href=\"browse\">Go back</a>")
else:
total_weight = 0
items = OrderDetail.objects.filter(orderID=current_order)
template_name = 'store/checkout.html'
order_details = []
for item in items:
weight = item.supplyID.weight * item.quantity
order_details.append((item, weight))
return render(request, template_name, {'order_details': order_details, 'current_order': current_order})
This is my template
<h1>Your current order</h1>
<a href="{% url 'Store:browse' %}">return to selecting
supplies</a><br><br>
<table>
<tr><th>name</th><th>item weight(kg)</th><th>qty</th><th>total
weight(kg)</th></tr>
{% for order_detail, weight in order_details %}
<tr>
<td>{{ order_detail.supplyID.name }}</td>
<td>{{ order_detail.supplyID.weight }}</td>
<td>{{ order_detail.quantity }}</td>
<td>{{ weight }}</td>
</tr>
{% endfor %}
</table>
{{total_weight}}
and it didn't seem to work – Nayo xx Nov 19 '18 at 16:49