debug in_stuck and has_discount filter for product list view
price range has still some bugs
This commit is contained in:
@@ -101,7 +101,7 @@ class AllProductsView(APIView):
|
|||||||
name="sort",
|
name="sort",
|
||||||
description=(
|
description=(
|
||||||
"Sort results by one of the following fields:\n"
|
"Sort results by one of the following fields:\n"
|
||||||
"`name`, `-name`, `price`, `-price`, `discount`, `-discount`, `created_at`, `-created_at`."
|
"`name`, `-name`, `price`, `-price`, `created_at`, `-created_at`."
|
||||||
"\nPrefix with `-` for descending order."
|
"\nPrefix with `-` for descending order."
|
||||||
),
|
),
|
||||||
required=False,
|
required=False,
|
||||||
@@ -158,12 +158,12 @@ class AllProductsView(APIView):
|
|||||||
# Filter by stock status if `in_stock` is specified
|
# Filter by stock status if `in_stock` is specified
|
||||||
in_stock = request.query_params.get('in_stock', "false") == 'true'
|
in_stock = request.query_params.get('in_stock', "false") == 'true'
|
||||||
if in_stock:
|
if in_stock:
|
||||||
products = products.filter(in_stock__gt=0)
|
products = products.filter(variants__in_stock__gt=0)
|
||||||
|
|
||||||
# Filter by discount if `has_discount` is specified
|
# Filter by discount if `has_discount` is specified
|
||||||
has_discount = request.query_params.get('has_discount', "false") == 'true'
|
has_discount = request.query_params.get('has_discount', "false") == 'true'
|
||||||
if has_discount:
|
if has_discount:
|
||||||
products = products.filter(discount__gt=0)
|
products = products.filter(variants__discount__gt=0)
|
||||||
|
|
||||||
# Search filter
|
# Search filter
|
||||||
search_query = request.query_params.get('search', None)
|
search_query = request.query_params.get('search', None)
|
||||||
@@ -175,13 +175,13 @@ class AllProductsView(APIView):
|
|||||||
price_lte = request.query_params.get('price_lte', None)
|
price_lte = request.query_params.get('price_lte', None)
|
||||||
|
|
||||||
if price_gte:
|
if price_gte:
|
||||||
products = products.filter(price__gte=price_gte)
|
products = products.filter(variants__min_price__gte=price_gte)
|
||||||
if price_lte:
|
if price_lte:
|
||||||
products = products.filter(price__lte=price_lte)
|
products = products.filter(variants__min_price__lte=price_lte)
|
||||||
|
|
||||||
# Sorting
|
# Sorting
|
||||||
sort_by = request.query_params.get('sort', None)
|
sort_by = request.query_params.get('sort', None)
|
||||||
if sort_by in ['name', '-name', 'price', '-price', 'discount', '-discount', 'created_at', '-created_at']:
|
if sort_by in ['name', '-name', 'price', '-price', 'created_at', '-created_at']:
|
||||||
products = products.order_by(sort_by)
|
products = products.order_by(sort_by)
|
||||||
else:
|
else:
|
||||||
products = products.order_by('name')
|
products = products.order_by('name')
|
||||||
|
|||||||
Reference in New Issue
Block a user