From cc27e4d96427c0cf69d6b58f7b68109d08856c4f Mon Sep 17 00:00:00 2001 From: Qwann Date: Thu, 22 Mar 2018 15:25:03 +0100 Subject: [PATCH] show not sold article in a different list --- kfet/templates/kfet/article.html | 46 ++++++++++++++++++++++++++++++-- kfet/views.py | 8 ++++++ 2 files changed, 52 insertions(+), 2 deletions(-) diff --git a/kfet/templates/kfet/article.html b/kfet/templates/kfet/article.html index 7966e797..8cec4279 100644 --- a/kfet/templates/kfet/article.html +++ b/kfet/templates/kfet/article.html @@ -7,8 +7,11 @@ @@ -25,6 +28,7 @@ {% endblock %} {% block main %} +

Article{{ articles|length|pluralize}} en vente

@@ -60,6 +64,44 @@
+ +

Articles non vendus

+

Article{{ not_sold_articles|length|pluralize }} non vendu{{ nots_sold_article|length|pluralize }}

+
+ + + + + + + + + + + + + {% for article in not_sold_articles %} + {% ifchanged article.category %} + + + + {% endifchanged %} + + + + + + + + + {% endfor %} + +
NomPrixStockEn venteAffichéDernier inventaire
{{ article.category.name }}
+ + {{ article.name }} + + {{ article.price }}€{{ article.stock }}{{ article.is_sold | yesno:"En vente,Non vendu"}}{{ article.hidden | yesno:"Caché,Affiché" }}{{ article.inventory.0.at }}
+
{% endblock %} diff --git a/kfet/views.py b/kfet/views.py index 2b69684d..63bd280c 100644 --- a/kfet/views.py +++ b/kfet/views.py @@ -706,6 +706,14 @@ class ArticleList(ListView): ) template_name = 'kfet/article.html' context_object_name = 'articles' + + def get_context_data(self, **kwargs): + context = super().get_context_data(**kwargs) + articles = context[self.context_object_name] + context['nb_articles'] = len(articles) + context[self.context_object_name] = articles.filter(is_sold=True) + context['not_sold_articles'] = articles.filter(is_sold=False) + return context # Article - Create