sort products by category weight on shop page
This commit is contained in:
parent
81fd6b30e5
commit
0cb7b688fa
18
src/shop/migrations/0060_productcategory_weight.py
Normal file
18
src/shop/migrations/0060_productcategory_weight.py
Normal 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.'),
|
||||
),
|
||||
]
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue