provedena paginacija
This commit is contained in:
parent
3931fc57bf
commit
6e89ea4000
Binary file not shown.
@ -1,25 +1,30 @@
|
|||||||
# views.py
|
# views.py
|
||||||
from rest_framework.views import APIView
|
from rest_framework.views import APIView
|
||||||
|
from rest_framework.generics import ListAPIView
|
||||||
from rest_framework.response import Response
|
from rest_framework.response import Response
|
||||||
from rest_framework import status
|
from rest_framework import status
|
||||||
from rest_framework import generics
|
from rest_framework import generics
|
||||||
from django.http import Http404
|
|
||||||
from .models import ObjektSigurnosti
|
from .models import ObjektSigurnosti
|
||||||
from .serializers import ObjektSigurnostiSerializer
|
from .serializers import ObjektSigurnostiSerializer
|
||||||
from django.shortcuts import get_object_or_404
|
from django.shortcuts import get_object_or_404
|
||||||
|
from rest_framework.pagination import LimitOffsetPagination
|
||||||
|
|
||||||
|
|
||||||
|
class CustomObjektSigurnostiPagination(LimitOffsetPagination):
|
||||||
|
default_limit = 20
|
||||||
|
|
||||||
|
|
||||||
class ObjektSigurnostiList(generics.ListCreateAPIView):
|
class ObjektSigurnostiList(generics.ListCreateAPIView):
|
||||||
serializer_class = ObjektSigurnostiSerializer
|
serializer_class = ObjektSigurnostiSerializer
|
||||||
|
pagination_class = CustomObjektSigurnostiPagination
|
||||||
|
|
||||||
def get_queryset(self): #queryset je data iz database, listing and creating objects
|
def get_queryset(self): #queryset je data iz database, listing and creating objects
|
||||||
queryset = ObjektSigurnosti.objects.all()
|
queryset = ObjektSigurnosti.objects.all()
|
||||||
location = self.request.query_params.get('lokacija')
|
location = self.request.query_params.get('lokacija')
|
||||||
if location is not None:
|
if location is not None:
|
||||||
queryset = queryset.filter(lokacija__icontains=location)
|
queryset = queryset.filter(lokacija__icontains=location)
|
||||||
return queryset
|
return queryset
|
||||||
|
|
||||||
# def get_serializer_class(self):
|
# def get_serializer_class(self):
|
||||||
# if self.request.method == "GET":
|
# if self.request.method == "GET":
|
||||||
# return ObjektSigurnostiSerializer
|
# return ObjektSigurnostiSerializer
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user