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;
This commit is contained in:
parent
d917584829
commit
40c86c7eef
1 changed files with 4 additions and 8 deletions
|
|
@ -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)),
|
||||
|
|
|
|||
Loading…
Reference in a new issue