sort products by category weight on shop page

This commit is contained in:
Thomas Steen Rasmussen 2019-12-16 23:41:05 +01:00
parent 81fd6b30e5
commit 0cb7b688fa
3 changed files with 20 additions and 1 deletions

View file

@ -0,0 +1,18 @@
# Generated by Django 2.2.3 on 2019-12-16 22:40
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('shop', '0059_auto_20190718_2051'),
]
operations = [
migrations.AddField(
model_name='productcategory',
name='weight',
field=models.IntegerField(default=100, help_text='Sorting weight. Heavier items sink to the bottom.'),
),
]

View file

@ -376,6 +376,7 @@ class ProductCategory(CreatedUpdatedModel, UUIDModel):
name = models.CharField(max_length=150)
slug = models.SlugField()
public = models.BooleanField(default=True)
weight = models.IntegerField(default=100, help_text="Sorting weight. Heavier items sink to the bottom.")
def __str__(self):
return self.name

View file

@ -156,7 +156,7 @@ class ShopIndexView(ListView):
def get_queryset(self):
queryset = super(ShopIndexView, self).get_queryset()
return queryset.available().order_by("category__name", "price", "name")
return queryset.available().order_by("category__weight", "category__name", "price", "name")
def get_context_data(self, **kwargs):
context = super(ShopIndexView, self).get_context_data(**kwargs)