Django Rest Framweork - Why first pagination offset starts from 0 and how to change it to 1?

Viewed 320

I am trying to create a custom Limit and Offset Paginator but first page starts from zero which I don't know why!.

The offset limit is set to 1 but within url it starts from 0, what I want is to start offset from 1 which in my case is page parameter, so by ?page=1&size=1 I got the second item inside data, if I changed page to 0 then it will return the first item which a little bit strange!!

from rest_framework.pagination import LimitOffsetPagination

min_num = 10
max_num = 50

class ApiPagination(LimitOffsetPagination):

    default_page = 1
    min_limit = min_num
    max_limit = max_num
    min_offset = min_num
    max_offset = max_num
    limit_query_param = 'size'
    offset_query_param = 'page'


    def get_paginated_response(self, data):
        next_url = self.get_next_link()
        previous_url = self.get_previous_link()
        first_url = self.get_first_link()
        last_url = self.get_last_link()

        return Response(
            {
                'Data': data,
                'Links': {
                    'Self': first_url,
                    'Last': last_url,
                    'First': first_url,
                    'Next': next_url,
                    'Prev': previous_url,
                },
                'Meta': {
                    'TotalPages': self.count - self.limit if self.offset not in [0, 1] else 1,
                    'Count': self.count,
                }
            }
        )


    def get_first_link(self): pass


    def get_last_link(self): pass
0 Answers
Related