Don't show non-active products. Also don't show categories which doesn't have any active products.

This commit is contained in:
Víðir Valberg Guðmundsson 2016-08-25 12:04:47 +02:00
parent 77422417ec
commit 029ec74389
2 changed files with 9 additions and 2 deletions

View file

@ -49,7 +49,7 @@ Shop | {{ block.super }}
</tr> </tr>
{% endifchanged %} {% endifchanged %}
<tr {% if not product.is_available %}class="text-muted"{% endif %}> <tr>
<td> <td>
<a href="{% url 'shop:product_detail' slug=product.slug %}"> <a href="{% url 'shop:product_detail' slug=product.slug %}">
{{ product.name }} {{ product.name }}
@ -61,6 +61,12 @@ Shop | {{ block.super }}
</div> </div>
</td> </td>
</tr> </tr>
{% empty %}
<tr>
<td colspan="2">
Sorry no products found.
</td>
</tr>
{% endfor %} {% endfor %}
</tbody> </tbody>
</table> </table>

View file

@ -171,7 +171,7 @@ class ShopIndexView(ListView):
def get_queryset(self): def get_queryset(self):
queryset = super(ShopIndexView, self).get_queryset() queryset = super(ShopIndexView, self).get_queryset()
return queryset.order_by('category__name', 'price', 'name') return queryset.available().order_by('category__name', 'price', 'name')
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)
@ -197,6 +197,7 @@ class ShopIndexView(ListView):
).filter( ).filter(
num_products__gt=0, num_products__gt=0,
public=True, public=True,
products__available_in__contains=timezone.now()
) )
return context return context