Merge pull request #46 from bornhack/categorise_shop_list

Catagorise product list for better overview
This commit is contained in:
Víðir Valberg Guðmundsson 2016-06-03 20:54:00 +02:00
commit ede9adc250
2 changed files with 16 additions and 4 deletions

View file

@ -27,22 +27,30 @@
<thead> <thead>
<tr> <tr>
<th>Product</th> <th>Product</th>
<th>Category</th>
<th class="pull-right">Price</th> <th class="pull-right">Price</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
{% for product in products %} {% for product in products %}
{% ifchanged product.category %}
<tr style="background-color: #cccccc">
<td colspan="2">
<strong>
{{ product.category }}
</strong>
</td>
</td>
</tr>
{% endifchanged %}
<tr {% if not product.is_available %}class="text-muted"{% endif %}> <tr {% if not product.is_available %}class="text-muted"{% endif %}>
<td> <td>
<a href="{% url 'shop:product_detail' slug=product.slug %}"> <a href="{% url 'shop:product_detail' slug=product.slug %}">
{{ product.name }} {{ product.name }}
</a> </a>
</td> </td>
<td>
{{ product.category }}
</td>
<td> <td>
<div class="pull-right"> <div class="pull-right">
{{ product.price|currency }} {{ product.price|currency }}

View file

@ -141,6 +141,10 @@ class ShopIndexView(ListView):
template_name = "shop_index.html" template_name = "shop_index.html"
context_object_name = 'products' context_object_name = 'products'
def get_queryset(self):
queryset = super(ShopIndexView, self).get_queryset()
return queryset.order_by('category__name', 'price')
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
context = super(ShopIndexView, self).get_context_data(**kwargs) context = super(ShopIndexView, self).get_context_data(**kwargs)