-1

I have a class in Python:

class CursorSetPagination(CursorPagination):
    page_size = 1
    page_size_query_param = 'per_page'
    ordering = '-posted_on'

I want to call this class with change statement page_size = 5 in it. I tried with this code:

paginator = CursorSetPagination(page_size = 5)

It doesn't work. How can I do this?

halfer
  • 19,824
  • 17
  • 99
  • 186
KitKit
  • 8,549
  • 12
  • 56
  • 82

1 Answers1

3

Use __init__ for it. Refer this answer for better understanding.

class CursorSetPagination(CursorPagination):
    def __init__(self, page_size=1, page_size_query_param='per_page', ordering):
        self.page_size = page_size
        self.page_size_query_param = 'page_size_query_param '
        self.ordering = ordering

You can reset the parameters used in __init__ this as below:

paginator = CursorSetPagination(page_size = 5)
Sociopath
  • 13,068
  • 19
  • 47
  • 75
  • Socialpath. Thanks. I will pick you best. But I dont know why people dislike my question. Maybe this is a stupid question right? – KitKit Dec 03 '18 at 09:18
  • 1
    No clue why people are downvoting your question. I think this question is genuine. – Sociopath Dec 03 '18 at 09:19