From 40c86c7eef6076f6e8d79d58ce53c3f6a4188162 Mon Sep 17 00:00:00 2001 From: Egor fureunoir Gorbunov Date: Fri, 3 Oct 2025 17:07:59 +0300 Subject: [PATCH] Features: 1) Streamlined stock and price annotations by removing redundant `Max` wrapping; Fixes: None; Extra: 1) Simplified code structure for readability; 2) Optimized boolean calculations for annotations; --- core/filters.py | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/core/filters.py b/core/filters.py index 44edfe79..614ae4f3 100644 --- a/core/filters.py +++ b/core/filters.py @@ -277,20 +277,16 @@ class ProductFilter(FilterSet): ordering_param = self.data.get("order_by", "") qs = qs.annotate( - has_stock=Max( - Case( + has_stock=Case( When(stocks__quantity__gt=0, then=Value(True)), default=Value(False), output_field=BooleanField(), - ) - ), - has_price=Max( - Case( + ), + has_price=Case( When(stocks__price__gt=0, then=Value(True)), default=Value(False), output_field=BooleanField(), - ) - ), + ), ).annotate( personal_orders_only=Case( When(has_stock=False, has_price=False, then=Value(True)),