show not sold article in a different list

This commit is contained in:
Qwann 2018-03-22 15:25:03 +01:00
parent 307c48ca76
commit cc27e4d964
2 changed files with 52 additions and 2 deletions

View file

@ -7,8 +7,11 @@
<aside>
<div class="heading">
{{ articles|length }}
<span class="sub">article{{ articles|length|pluralize }}</span>
{{ nb_articles }}
<span class="sub">article{{ nb_articles|pluralize }}</span>
</div>
<div class="heading">
<span class="sub">dont {{ articles|length }} en vente</span>
</div>
</aside>
@ -25,6 +28,7 @@
{% endblock %}
{% block main %}
<h2>Article{{ articles|length|pluralize}} en vente</h2>
<div class="table-responsive">
<table class="table table-hover table-condensed">
<thead>
@ -60,6 +64,44 @@
</tbody>
</table>
</div>
<h2>Articles non vendus</h2>
<h2>Article{{ not_sold_articles|length|pluralize }} non vendu{{ nots_sold_article|length|pluralize }}</h2>
<div class="table-responsive">
<table class="table table-hover table-condensed">
<thead>
<tr>
<td>Nom</td>
<td class="text-right">Prix</td>
<td class="text-right">Stock</td>
<td class="text-right">En vente</td>
<td class="text-right">Affiché</td>
<td class="text-right">Dernier inventaire</td>
</tr>
</thead>
<tbody>
{% for article in not_sold_articles %}
{% ifchanged article.category %}
<tr class="section">
<td colspan="6">{{ article.category.name }}</td>
</tr>
{% endifchanged %}
<tr>
<td>
<a href="{% url 'kfet.article.read' article.pk %}">
{{ article.name }}
</a>
</td>
<td class="text-right">{{ article.price }}€</td>
<td class="text-right">{{ article.stock }}</td>
<td class="text-right">{{ article.is_sold | yesno:"En vente,Non vendu"}}</td>
<td class="text-right">{{ article.hidden | yesno:"Caché,Affiché" }}</td>
<td class="text-right">{{ article.inventory.0.at }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
{% endblock %}

View file

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