product create fix error
This commit is contained in:
23
core/apps/vendors/pagination.py
vendored
23
core/apps/vendors/pagination.py
vendored
@@ -1,6 +1,27 @@
|
||||
from rest_framework.pagination import CursorPagination
|
||||
from rest_framework.pagination import CursorPagination, PageNumberPagination
|
||||
|
||||
|
||||
class VendorProductCursorPagination(CursorPagination):
|
||||
page_size = 20
|
||||
ordering = '-created_at'
|
||||
cursor_query_param = 'cursor'
|
||||
|
||||
|
||||
class VendorProductPagePagination(PageNumberPagination):
|
||||
page_size = 20
|
||||
page_size_query_param = 'page_size'
|
||||
max_page_size = 100
|
||||
|
||||
def get_paginated_response(self, data):
|
||||
from rest_framework.response import Response
|
||||
return Response({
|
||||
"total_items": self.page.paginator.count,
|
||||
"total_pages": self.page.paginator.num_pages,
|
||||
"page_size": self.get_page_size(self.request),
|
||||
"current_page": self.page.number,
|
||||
"links": {
|
||||
"next": self.get_next_link(),
|
||||
"previous": self.get_previous_link(),
|
||||
},
|
||||
"results": data,
|
||||
})
|
||||
|
||||
16
core/apps/vendors/views/vendor_product.py
vendored
16
core/apps/vendors/views/vendor_product.py
vendored
@@ -14,10 +14,11 @@ from core.apps.vendors.serializers.vendor_product import (
|
||||
)
|
||||
|
||||
|
||||
from rest_framework.filters import SearchFilter
|
||||
from rest_framework.viewsets import ModelViewSet
|
||||
from django_filters.rest_framework import DjangoFilterBackend
|
||||
from core.apps.vendors.filters.vendor_product import ProductimageFilter, VendorproductFilter
|
||||
from core.apps.vendors.pagination import VendorProductCursorPagination
|
||||
from core.apps.vendors.pagination import VendorProductPagePagination
|
||||
|
||||
from django.shortcuts import get_object_or_404
|
||||
from django.db.models import Q
|
||||
@@ -28,9 +29,18 @@ class VendorproductView(BaseViewSetMixin, ModelViewSet):
|
||||
lookup_field = "firestore_id"
|
||||
serializer_class = ListVendorproductSerializer
|
||||
permission_classes = [AllowAny]
|
||||
pagination_class = VendorProductCursorPagination
|
||||
filter_backends = [DjangoFilterBackend]
|
||||
pagination_class = VendorProductPagePagination
|
||||
filter_backends = [DjangoFilterBackend, SearchFilter]
|
||||
filterset_class = VendorproductFilter
|
||||
search_fields = ["name", "description"]
|
||||
|
||||
def get_queryset(self):
|
||||
qs = super().get_queryset()
|
||||
# vendor param berilsa — faqat o'sha vendorning mahsulotlari
|
||||
vendor_id = self.request.query_params.get("vendor")
|
||||
if vendor_id:
|
||||
qs = qs.filter(vendor=vendor_id)
|
||||
return qs
|
||||
|
||||
action_permission_classes = {}
|
||||
action_serializer_class = {
|
||||
|
||||
Reference in New Issue
Block a user