place list uchun tuman boyicha filter qoshildi
This commit is contained in:
@@ -6,6 +6,7 @@ from rest_framework import generics, permissions
|
|||||||
|
|
||||||
# drf yasg
|
# drf yasg
|
||||||
from drf_yasg.utils import swagger_auto_schema
|
from drf_yasg.utils import swagger_auto_schema
|
||||||
|
from drf_yasg import openapi
|
||||||
|
|
||||||
# shared
|
# shared
|
||||||
from core.apps.shared.models import Place
|
from core.apps.shared.models import Place
|
||||||
@@ -23,6 +24,15 @@ class PlaceListApiView(generics.GenericAPIView, ResponseMixin):
|
|||||||
permission_classes = [permissions.IsAuthenticated]
|
permission_classes = [permissions.IsAuthenticated]
|
||||||
|
|
||||||
@swagger_auto_schema(
|
@swagger_auto_schema(
|
||||||
|
manual_parameters=[
|
||||||
|
openapi.Parameter(
|
||||||
|
name="district_id",
|
||||||
|
in_=openapi.IN_QUERY,
|
||||||
|
description="Tuman boyicha filterlash",
|
||||||
|
type=openapi.TYPE_INTEGER,
|
||||||
|
required=False
|
||||||
|
)
|
||||||
|
],
|
||||||
responses={
|
responses={
|
||||||
200: base_serializer.SuccessResponseSerializer(),
|
200: base_serializer.SuccessResponseSerializer(),
|
||||||
400: base_serializer.BaseResponseSerializer(),
|
400: base_serializer.BaseResponseSerializer(),
|
||||||
@@ -32,10 +42,12 @@ class PlaceListApiView(generics.GenericAPIView, ResponseMixin):
|
|||||||
def get(self, request):
|
def get(self, request):
|
||||||
try:
|
try:
|
||||||
search = request.query_params.get('search')
|
search = request.query_params.get('search')
|
||||||
|
district_id = request.query_params.get('district_id')
|
||||||
query = self.queryset.filter(user=request.user)
|
query = self.queryset.filter(user=request.user)
|
||||||
if search:
|
if search:
|
||||||
query = query.filter(name__istartswith=search)
|
query = query.filter(name__istartswith=search)
|
||||||
|
if district_id:
|
||||||
|
query = query.filter(district__id=district_id)
|
||||||
|
|
||||||
page = self.paginate_queryset(query)
|
page = self.paginate_queryset(query)
|
||||||
if page is not None:
|
if page is not None:
|
||||||
|
|||||||
Reference in New Issue
Block a user