feat(category): add min_price and max_price to serializer
enable retrieval of min and max product prices for categories to support price range filters. fixed a typo in queryset filter for brands.
This commit is contained in:
parent
f664b088a4
commit
a1cc0cfd30
2 changed files with 10 additions and 2 deletions
|
|
@ -456,8 +456,8 @@ class Category(NiceModel, MPTTModel):
|
|||
@cached_property
|
||||
def brands(self) -> QuerySet["Brand"]:
|
||||
return Brand.objects.filter(
|
||||
products__category=self,
|
||||
products__is_active=True,
|
||||
product__category=self,
|
||||
product__is_active=True,
|
||||
is_active=True,
|
||||
).distinct()
|
||||
|
||||
|
|
|
|||
|
|
@ -62,6 +62,8 @@ class CategoryDetailSerializer(ModelSerializer):
|
|||
children = SerializerMethodField()
|
||||
filterable_attributes = SerializerMethodField()
|
||||
brands = BrandSimpleSerializer(many=True, read_only=True)
|
||||
min_price = SerializerMethodField()
|
||||
max_price = SerializerMethodField()
|
||||
|
||||
class Meta:
|
||||
model = Category
|
||||
|
|
@ -98,6 +100,12 @@ class CategoryDetailSerializer(ModelSerializer):
|
|||
return list(serializer.data)
|
||||
return []
|
||||
|
||||
def get_min_price(self, obj: Category):
|
||||
return obj.min_price
|
||||
|
||||
def get_max_price(self, obj: Category):
|
||||
return obj.max_price
|
||||
|
||||
|
||||
class BrandDetailSerializer(ModelSerializer):
|
||||
categories = CategorySimpleSerializer(many=True)
|
||||
|
|
|
|||
Loading…
Reference in a new issue