Skip to content

Commit

Permalink
feature(pagination): pagination for articles
Browse files Browse the repository at this point in the history
-enable pagination for articles

[feature #161255368]
  • Loading branch information
3N61N33R committed Nov 14, 2018
1 parent 9257741 commit 7e2a7f3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
9 changes: 6 additions & 3 deletions authors/apps/articles/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from django.shortcuts import render
from django.shortcuts import render, get_object_or_404
from rest_framework.generics import CreateAPIView, RetrieveUpdateAPIView
from rest_framework.pagination import LimitOffsetPagination
from rest_framework.permissions import (
AllowAny, IsAuthenticated, IsAuthenticatedOrReadOnly,)
from rest_framework.response import Response
Expand All @@ -18,6 +19,8 @@
class ArticlesView(viewsets.ModelViewSet):
permission_classes = (IsAuthenticatedOrReadOnly,)
serializer_class = ArticleSerializer
queryset = Article.objects.all()
pagination_class = LimitOffsetPagination

def check_article_exists(self, slug):
'''method checking if article exists'''
Expand All @@ -30,10 +33,10 @@ def check_article_exists(self, slug):

def list(self, request):
serializer_context = {'request': request}
queryset = Article.objects.all()
page = self.paginate_queryset(self.queryset)
serializer = self.serializer_class(
queryset, context=serializer_context, many=True)
return Response(serializer.data, status=status.HTTP_200_OK)
page, context=serializer_context, many=True)
return self.get_paginated_response(serializer.data)

def create(self, request):
'''method creating a new article(post)'''
Expand Down
2 changes: 2 additions & 0 deletions authors/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,8 @@
'DEFAULT_AUTHENTICATION_CLASSES': (
'authors.apps.authentication.backends.JWTAuthentication',
),
'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.LimitOffsetPagination',
'PAGE_SIZE' : 10,
}

# Sendgrid settings
Expand Down

0 comments on commit 7e2a7f3

Please sign in to comment.