I am trying to do for pagination and reading through this link.
Pagination in Django-Rest-Framework using API-View
I need to have next, previous url for pagination. Problem is that when I call this one,
pagination_class = settings.DEFAULT_PAGINATION_CLASS
It say
'Settings' object has no attribute 'DEFAULT_PAGINATION_CLASS'
What do I need to import? or install ?
Models.py
class CarView(APIView):
permission_classes = ()
def get(self, request):
""" Get all car """
car = Car.objects.all()
# paginator = PageNumberPagination()
serializer = CarSerializer(car)
serialized_car = CarSerializer(car, context={"request": request})
# serializer = CarSerializer(car[0])
return Response(serialized_car.data)
Serializers.py
class CarSerializer(serializers.ModelSerializer):
photo_url = serializers.SerializerMethodField('get_photo_url')
class Meta:
model = Car
fields = ('id','name','price', 'photo_url')
def get_photo_url(self, car):
request = self.context.get('request')
photo_url = car.photo.url
return request.build_absolute_uri(photo_url)
settings.py
REST_FRAMEWORK = {
'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination',
'PAGE_SIZE': 100,
'DEFAULT_AUTHENTICATION_CLASSES':
('rest_framework.authentication.OAuth2Authentication',
'rest_framework.authentication.SessionAuthentication'),
'DEFAULT_MODEL_SERIALIZER_CLASS':
'rest_framework.serializers.ModelSerializer',
'DEFAULT_PERMISSION_CLASSES':
('rest_framework.permissions.IsAdminUser',)
}