From 8a14643ad4f1b8030e9ce224cb7d26f842cec2b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Delobelle?= Date: Tue, 30 Aug 2016 18:16:57 +0200 Subject: [PATCH] Liste articles --- kfet/templates/kfet/article.html | 63 +++++++++++++++++++++++++++----- kfet/views.py | 8 +++- 2 files changed, 60 insertions(+), 11 deletions(-) diff --git a/kfet/templates/kfet/article.html b/kfet/templates/kfet/article.html index 8fb844b7..387806bd 100644 --- a/kfet/templates/kfet/article.html +++ b/kfet/templates/kfet/article.html @@ -6,17 +6,62 @@ {% block content %}
-
-
- Créer un article +
+
+
+
{{ articles|length }}
+
article{{ articles|length|pluralize }}
+
+ +
+
+
+ {% include 'kfet/base_messages.html' %} +
+
+

Liste des articles

+
+ + + + + + + + + + + + + {% for article in articles %} + {% ifchanged article.category %} + + + + {% endifchanged %} + + + + + + + + + {% endfor %} + +
NomPrixStockEn venteDernier inventaire
{{ article.category.name }}
+ + + + {{ article.name }}{{ article.price }}{{ article.stock }}{{ article.is_sold }}{{ article.inventory.0.at }}
+
+
- - {% endblock %} diff --git a/kfet/views.py b/kfet/views.py index 77fd2329..6cdaa83a 100644 --- a/kfet/views.py +++ b/kfet/views.py @@ -542,8 +542,12 @@ class CheckoutStatementUpdate(SuccessMessageMixin, UpdateView): # Article - General class ArticleList(ListView): - model = Article - queryset = Article.objects.order_by('category', '-is_sold', 'name') + queryset = (Article.objects + .select_related('category') + .prefetch_related(Prefetch('inventories', + queryset = Inventory.objects.order_by('-at'), + to_attr = 'inventory')) + .order_by('category', '-is_sold', 'name')) template_name = 'kfet/article.html' context_object_name = 'articles'