From ed3ad7cda0d588b8849aff6524036e3778f97ba0 Mon Sep 17 00:00:00 2001 From: RubenPX Date: Fri, 11 Mar 2022 17:36:51 +0100 Subject: [PATCH 1/3] format date using ES Format --- musician/views.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/musician/views.py b/musician/views.py index 1bdc69b..3ab4265 100644 --- a/musician/views.py +++ b/musician/views.py @@ -1,5 +1,6 @@ import logging import smtplib +import datetime from django.conf import settings from django.contrib import messages @@ -181,6 +182,8 @@ class BillingView(ServiceListView): def get_queryset(self): qs = super().get_queryset() qs = sorted(qs, key=lambda x: x.created_on, reverse=True) + for q in qs: + q.created_on = datetime.datetime.strptime(q.created_on, "%Y-%m-%d").strftime("%d/%m/%Y") return qs From c1f25a73da8e4b7c42f168f9316b3e615fe9f4d5 Mon Sep 17 00:00:00 2001 From: RubenPX Date: Thu, 17 Mar 2022 19:23:36 +0100 Subject: [PATCH 2/3] refactor to use django template string --- musician/templates/musician/billing.html | 2 +- musician/views.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/musician/templates/musician/billing.html b/musician/templates/musician/billing.html index d3ba915..e02c6b0 100644 --- a/musician/templates/musician/billing.html +++ b/musician/templates/musician/billing.html @@ -27,7 +27,7 @@ {% for bill in object_list %} {{ bill.number }} - {{ bill.created_on }} + {{ bill.created_on|date:"d/m/Y" }} {{ bill.type }} {{ bill.total|floatformat:2|localize }}€ diff --git a/musician/views.py b/musician/views.py index 3ab4265..ec3ac36 100644 --- a/musician/views.py +++ b/musician/views.py @@ -183,7 +183,7 @@ class BillingView(ServiceListView): qs = super().get_queryset() qs = sorted(qs, key=lambda x: x.created_on, reverse=True) for q in qs: - q.created_on = datetime.datetime.strptime(q.created_on, "%Y-%m-%d").strftime("%d/%m/%Y") + q.created_on = datetime.datetime.strptime(q.created_on, "%Y-%m-%d") return qs From 41f54933688e3b5bba0917bfee80851b9df26297 Mon Sep 17 00:00:00 2001 From: Santiago L Date: Thu, 17 Mar 2022 22:34:54 +0100 Subject: [PATCH 3/3] Format date using SHORT_DATE_FORMAT Support automatically i18n on date format --- musician/templates/musician/billing.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/musician/templates/musician/billing.html b/musician/templates/musician/billing.html index e02c6b0..75f2580 100644 --- a/musician/templates/musician/billing.html +++ b/musician/templates/musician/billing.html @@ -27,7 +27,7 @@ {% for bill in object_list %} {{ bill.number }} - {{ bill.created_on|date:"d/m/Y" }} + {{ bill.created_on|date:"SHORT_DATE_FORMAT" }} {{ bill.type }} {{ bill.total|floatformat:2|localize }}€