Skip to content

Commit

Permalink
Added general Pagination class
Browse files Browse the repository at this point in the history
  • Loading branch information
OlegatorLE committed Oct 22, 2023
1 parent 8d16ee6 commit 1c13841
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions airport/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,16 @@
)


class Pagination(PageNumberPagination):
page_size = 3
page_size_query_param = "page_size"
max_page_size = 100


class AirportViewSet(viewsets.ModelViewSet):
queryset = Airport.objects.all()
serializer_class = AirportSerializer
pagination_class = Pagination
permission_classes = (IsAdminOrIfAuthenticatedReadOnly,)

def get_queryset(self):
Expand Down Expand Up @@ -155,12 +162,6 @@ def get_queryset(self):
return queryset


class OrderPagination(PageNumberPagination):
page_size = 1
page_size_query_param = "page_size"
max_page_size = 100


class OrderViewSet(viewsets.ModelViewSet):
flight_prefetch = Prefetch(
"tickets__flight",
Expand All @@ -172,7 +173,7 @@ class OrderViewSet(viewsets.ModelViewSet):

serializer_class = OrderSerializer
permission_classes = (IsAuthenticated,)
pagination_class = OrderPagination
pagination_class = Pagination

def get_queryset(self):
return self.queryset.filter(user=self.request.user)
Expand Down

0 comments on commit 1c13841

Please sign in to comment.