Skip to content

Commit

Permalink
ft(upgrade):pagination support for articles
Browse files Browse the repository at this point in the history
- add function in list all views to paginate articles
- import paginator from django framework

[DELIVERS #160617682]

ft(maintain):add a defaults pagination class to settings
  • Loading branch information
Amos Welike authored and AmosWels committed Oct 12, 2018
1 parent e869070 commit f64cb6a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
7 changes: 3 additions & 4 deletions authors/apps/articles/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@
from authors.apps.articles.serializers import ArticleSerializer
from rest_framework.exceptions import PermissionDenied
from .models import Article
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
from rest_framework import serializers
from django.core.exceptions import ObjectDoesNotExist


class ArticleAPIView(generics.ListCreateAPIView):
"""create an article, list all articles """
"""create an article, list all articles paginated to 5 per page"""
queryset = Article.objects.all()
permission_classes = (IsAuthenticatedOrReadOnly,)
renderer_classes = (ArticleJSONRenderer,)
Expand All @@ -28,9 +27,9 @@ def create(self, request, *args, **kwargs):
return Response(serializer.data, status=status.HTTP_201_CREATED, headers=headers)

def perform_create(self, serializer):
serializer.save(author=self.request.user)
serializer.save(author=self.request.user)



class ArticleAPIDetailsView(generics.RetrieveUpdateDestroyAPIView):
"""retreive, update and delete an article """
permission_classes = (IsAuthenticatedOrReadOnly,)
Expand Down
2 changes: 2 additions & 0 deletions authors/settings/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@
REST_FRAMEWORK = {
'EXCEPTION_HANDLER': 'authors.apps.core.exceptions.core_exception_handler',
'NON_FIELD_ERRORS_KEY': 'error',
'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination',
'PAGE_SIZE': 5,

'DEFAULT_AUTHENTICATION_CLASSES': (
'authors.apps.authentication.backends.JWTAuthentication',
Expand Down

0 comments on commit f64cb6a

Please sign in to comment.