diff --git a/core/filters.py b/core/filters.py index 5a332beb..b773c3b7 100644 --- a/core/filters.py +++ b/core/filters.py @@ -87,7 +87,7 @@ class ProductFilter(FilterSet): ("slug", "slug"), ("created", "created"), ("modified", "modified"), - ("price", "price"), + ("price_order", "price"), ("?", "random"), ), initial="uuid", @@ -134,7 +134,7 @@ class ProductFilter(FilterSet): ) if "price" in order_fields: self.queryset = self.queryset.annotate( - price=Coalesce( + price_order=Coalesce( Max("stocks__price"), Value(0.0), output_field=FloatField(), diff --git a/core/models.py b/core/models.py index dca0c750..0d3c5384 100644 --- a/core/models.py +++ b/core/models.py @@ -609,7 +609,7 @@ class Product(ExportModelOperationsMixin("product"), NiceModel): # type: ignore Properties: rating (float): The average rating of the product, rounded to 2 decimal places. feedbacks_count (int): The total number of feedback entries associated with the product. - price (float): The lowest price of the product based on its stock, rounded to 2 decimal + price (float): The highest price of the product based on its stock, rounded to 2 decimal places. quantity (int): The total available quantity of the product across all its stocks. total_orders (int): Counts the total orders made for the product in relevant statuses. diff --git a/core/viewsets.py b/core/viewsets.py index 69250806..d213b516 100644 --- a/core/viewsets.py +++ b/core/viewsets.py @@ -571,19 +571,11 @@ class ProductViewSet(EvibesViewSet): @action(detail=True, methods=["get"], url_path="feedbacks") def feedbacks(self, request, **kwargs): - lookup_val = kwargs.get(self.lookup_field) - try: - product = Product.objects.get(uuid=lookup_val) - feedbacks = ( - Feedback.objects.filter(order_product__product=product) - if request.user.has_perm("core.view_feedback") - else Feedback.objects.filter(order_product__product=product, is_active=True) - ) - # noinspection PyTypeChecker - return Response(data=FeedbackDetailSerializer(feedbacks, many=True).data) - except Product.DoesNotExist: - name = "Product" - return Response(status=status.HTTP_404_NOT_FOUND, data={"detail": _(f"{name} does not exist: {uuid}")}) + product = self.get_object() + qs = Feedback.objects.filter(order_product__product=product) + if not request.user.has_perm("core.view_feedback"): + qs = qs.filter(is_active=True) + return Response(data=FeedbackDetailSerializer(qs, many=True).data) @action( detail=True,