Commit c4a8e6cefa5d1df8587edb71a15a260a2b8bd90a
1 parent
c6ec352e71
Exists in
master
Added pagination sections and lectureperiods
Showing 1 changed file with 9 additions and 0 deletions Inline Diff
flashcards/views.py
View file @
c4a8e6c
from flashcards.models import Section, LecturePeriod | 1 | 1 | from flashcards.models import Section, LecturePeriod | |
from flashcards.serializers import SectionSerializer, LecturePeriodSerializer | 2 | 2 | from flashcards.serializers import SectionSerializer, LecturePeriodSerializer | |
from rest_framework.permissions import IsAuthenticatedOrReadOnly | 3 | 3 | from rest_framework.permissions import IsAuthenticatedOrReadOnly | |
from rest_framework.viewsets import ModelViewSet | 4 | 4 | from rest_framework.viewsets import ModelViewSet | |
5 | from rest_framework.pagination import PageNumberPagination | |||
6 | from django.core.paginator import Paginator | |||
5 | 7 | |||
8 | class StandardResultsSetPagination(PageNumberPagination): | |||
9 | page_size = 40 | |||
10 | page_size_query_param = 'page_size' | |||
11 | max_page_size = 1000 | |||
12 | ||||
class SectionViewSet(ModelViewSet): | 6 | 13 | class SectionViewSet(ModelViewSet): | |
queryset = Section.objects.all() | 7 | 14 | queryset = Section.objects.all() | |
serializer_class = SectionSerializer | 8 | 15 | serializer_class = SectionSerializer | |
permission_classes = (IsAuthenticatedOrReadOnly,) | 9 | 16 | permission_classes = (IsAuthenticatedOrReadOnly,) | |
17 | pagination_class = StandardResultsSetPagination | |||
10 | 18 | |||
class LecturePeriodViewSet(ModelViewSet): | 11 | 19 | class LecturePeriodViewSet(ModelViewSet): | |
queryset = LecturePeriod.objects.all() | 12 | 20 | queryset = LecturePeriod.objects.all() | |
serializer_class = LecturePeriodSerializer | 13 | 21 | serializer_class = LecturePeriodSerializer |