diff --git a/src/shop/migrations/0060_productcategory_weight.py b/src/shop/migrations/0060_productcategory_weight.py new file mode 100644 index 00000000..d4253dbb --- /dev/null +++ b/src/shop/migrations/0060_productcategory_weight.py @@ -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.'), + ), + ] diff --git a/src/shop/models.py b/src/shop/models.py index 929acd99..77505bf1 100644 --- a/src/shop/models.py +++ b/src/shop/models.py @@ -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 diff --git a/src/shop/views.py b/src/shop/views.py index 62f08f00..9e66d135 100644 --- a/src/shop/views.py +++ b/src/shop/views.py @@ -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)