debug multipule product show
This commit is contained in:
@@ -12,6 +12,7 @@ from drf_spectacular.utils import extend_schema, OpenApiParameter, OpenApiTypes
|
|||||||
from rest_framework.permissions import AllowAny
|
from rest_framework.permissions import AllowAny
|
||||||
from order.serializers import OrderItemSerailzier
|
from order.serializers import OrderItemSerailzier
|
||||||
from order.models import OrderModel
|
from order.models import OrderModel
|
||||||
|
from django.db.models import Min, Max
|
||||||
# class APIView(APIView):
|
# class APIView(APIView):
|
||||||
# def __init__(self, *args, **kwargs):
|
# def __init__(self, *args, **kwargs):
|
||||||
# super().__init__(*args, **kwargs)
|
# super().__init__(*args, **kwargs)
|
||||||
@@ -177,15 +178,16 @@ class AllProductsView(APIView):
|
|||||||
if search_query:
|
if search_query:
|
||||||
products = products.filter(Q(name__icontains=search_query) | Q(description__icontains=search_query))
|
products = products.filter(Q(name__icontains=search_query) | Q(description__icontains=search_query))
|
||||||
|
|
||||||
# # Price filters
|
# Price filters
|
||||||
price_gte = request.query_params.get('price_gte', None)
|
price_gte = request.query_params.get('price_gte', None)
|
||||||
price_lte = request.query_params.get('price_lte', None)
|
price_lte = request.query_params.get('price_lte', None)
|
||||||
|
|
||||||
if price_gte:
|
|
||||||
products = products.filter(variants__price__gte=price_gte)
|
|
||||||
if price_lte:
|
|
||||||
products = products.filter(variants__price__lte=price_lte)
|
|
||||||
|
|
||||||
|
products = products.annotate(min_price=Min('variants__price'), max_price=Max('variants__price'))
|
||||||
|
|
||||||
|
if price_gte:
|
||||||
|
products = products.filter(max_price__gte=price_gte)
|
||||||
|
if price_lte:
|
||||||
|
products = products.filter(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', 'created_at', '-created_at']:
|
if sort_by in ['name', '-name', 'created_at', '-created_at']:
|
||||||
|
|||||||
Reference in New Issue
Block a user