From 2e3ef91ec3629d4c62fc6286442a3b402064ada6 Mon Sep 17 00:00:00 2001 From: Titouan Vervack Date: Fri, 9 Mar 2018 00:59:33 +0100 Subject: [PATCH] Count and display total # of orders --- app/models.py | 6 ++++++ app/templates/order.html | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/app/models.py b/app/models.py index 5bec32f..9db3526 100644 --- a/app/models.py +++ b/app/models.py @@ -110,6 +110,12 @@ class Order(db.Model): return group + def len(self): + size = 0 + for _ in self.items: + size = size + 1 + return size + def group_by_product(self): group = dict() for item in self.items: diff --git a/app/templates/order.html b/app/templates/order.html index a0064b2..4ee0619 100644 --- a/app/templates/order.html +++ b/app/templates/order.html @@ -78,7 +78,7 @@
-

Ordered products: {% len(order.items) %}

+

Ordered products: {{ order.len() }}

{% for key, value in order.group_by_product().items() -%}
{{ key }}: {{ value["count"] }}