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,19 +277,15 @@ class ProductFilter(FilterSet):
|
||||||
ordering_param = self.data.get("order_by", "")
|
ordering_param = self.data.get("order_by", "")
|
||||||
|
|
||||||
qs = qs.annotate(
|
qs = qs.annotate(
|
||||||
has_stock=Max(
|
has_stock=Case(
|
||||||
Case(
|
|
||||||
When(stocks__quantity__gt=0, then=Value(True)),
|
When(stocks__quantity__gt=0, then=Value(True)),
|
||||||
default=Value(False),
|
default=Value(False),
|
||||||
output_field=BooleanField(),
|
output_field=BooleanField(),
|
||||||
)
|
|
||||||
),
|
),
|
||||||
has_price=Max(
|
has_price=Case(
|
||||||
Case(
|
|
||||||
When(stocks__price__gt=0, then=Value(True)),
|
When(stocks__price__gt=0, then=Value(True)),
|
||||||
default=Value(False),
|
default=Value(False),
|
||||||
output_field=BooleanField(),
|
output_field=BooleanField(),
|
||||||
)
|
|
||||||
),
|
),
|
||||||
).annotate(
|
).annotate(
|
||||||
personal_orders_only=Case(
|
personal_orders_only=Case(
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue