Count and display total # of orders

This commit is contained in:
Titouan Vervack 2018-03-09 00:59:33 +01:00
parent f9b48969b2
commit 2e3ef91ec3
2 changed files with 7 additions and 1 deletions

View file

@ -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:

View file

@ -78,7 +78,7 @@
</table>
</div>
<div class="col-md-push-2 col-md-4 darker" id="items-ordered">
<h3>Ordered products: {% len(order.items) %}</h3>
<h3>Ordered products: {{ order.len() }}</h3>
{% for key, value in order.group_by_product().items() -%}
<div class="product">
{{ key }}: {{ value["count"] }}