From 029ca1cf0062618217e36e3daf777a134ebdc93e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=AD=C3=B0ir=20Valberg=20Gu=C3=B0mundsson?= Date: Mon, 16 May 2016 20:56:52 +0200 Subject: [PATCH] Adding currency tags to display prices correct --- shop/templates/order_detail.html | 9 +++++---- shop/templates/shop_index.html | 3 ++- shop/templatetags/__init__.py | 0 shop/templatetags/shop_tags.py | 10 ++++++++++ 4 files changed, 17 insertions(+), 5 deletions(-) create mode 100644 shop/templatetags/__init__.py create mode 100644 shop/templatetags/shop_tags.py diff --git a/shop/templates/order_detail.html b/shop/templates/order_detail.html index 84048a20..6d9b72d6 100644 --- a/shop/templates/order_detail.html +++ b/shop/templates/order_detail.html @@ -1,5 +1,6 @@ {% extends 'base.html' %} {% load bootstrap3 %} +{% load shop_tags %} {% block content %} @@ -42,9 +43,9 @@ {{ order_product.quantity }} {% endif %} - {{ order_product.product.price }} + {{ order_product.product.price|currency }} - {{ order_product.total }} + {{ order_product.total|currency }} {% endfor %} @@ -53,14 +54,14 @@ Hereof VAT (25%) - {{ order.vat }} + {{ order.vat|currency }} Total - {{ order.total }} + {{ order.total|currency }} diff --git a/shop/templates/shop_index.html b/shop/templates/shop_index.html index 77b890b0..5c3406ab 100644 --- a/shop/templates/shop_index.html +++ b/shop/templates/shop_index.html @@ -1,5 +1,6 @@ {% extends 'base.html' %} {% load bootstrap3 %} +{% load shop_tags %} {% block content %} @@ -33,7 +34,7 @@

- Price: {{ product.price }} DKK + Price: {{ product.price|currency }}

diff --git a/shop/templatetags/__init__.py b/shop/templatetags/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/shop/templatetags/shop_tags.py b/shop/templatetags/shop_tags.py new file mode 100644 index 00000000..2aa6b95f --- /dev/null +++ b/shop/templatetags/shop_tags.py @@ -0,0 +1,10 @@ +from django import template + +register = template.Library() + + +@register.filter +def currency(value): + return "{0:.2f} DKK".format(value) + +