I am building an application that lists certain records from a database. The database is quite large and I am building a pagination to show a specific number of rows. Currently I have set a default value for the paginate_by. Here is the class that I am using.
class HomePageView(ListView):
model = Syslog
template_name = 'home.html'
context_object_name = 'all_logs';
paginate_by = 10
def get_paginate_by(self, queryset):
return self.request.GET.get("paginate_by", self.paginate_by)
I have implemented and a feature that allows clients to change the pagination levels like so:
<form action="" method="get">
<select name="paginate_by" onchange='this.form.submit()'>
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
</select>
</form>
I am building an application that lists certain records from a database. The database is quite large and I am building a pagination to show a specific number of rows. Currently I have set a default value for the paginate_by. Here is the class that I am using.
class HomePageView(ListView):
model = Syslog
template_name = 'home.html'
context_object_name = 'all_logs';
paginate_by = 10
def get_paginate_by(self, queryset):
return self.request.GET.get("paginate_by", self.paginate_by)
I have implemented and a feature that allows clients to change the pagination levels like so:
<form action="" method="get">
<select name="paginate_by" onchange='this.form.submit()'>
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
</select>
</form>
When the home page is loaded with the default value the number of pages show correctly. When a user submit another paginate_by value the number of pages change accordingly. The problem is that when the pagination parameter is changed and a user click on let's say 2nd page the paginate_by resets to the default.