Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#160617682 pagination support for articles #25

Merged
merged 1 commit into from
Oct 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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