The pagination is done in paginate_queryset
, called by get_context_data
, called by post
(that defaults to a subcall to get
) , so you can so something like (given you have a filter method that filters based on post data):
def post(self, request, *args, **kwargs):
self.queryset = self.filter(self.get_queryset())
return super(MyView, self).get(request, *args, **kwargs)
the parent post will call get_queryset
, that returns your filtered self.queryset
, and it will paginate it when calling get_context_data
to not display the queryset on the first get
,
def get(self, request, *args, **kwargs):
return self.self.response_class(
request=self.request,
template=self.get_template_names())
the pagination template link should always post to the view instead of the default get so save the search input in the context and change the template for the pagination, with
def get_context_data(self, **kwargs):
context = super(MyView, self).get_context_data(**kwargs)
context['search_value'] = self.request.POST.get('search_name', None)
return context
,
<form action="?page={{ page_obj.previous_page_number }}" method="post">
{% csrf_token %}
<input type="hidden" value="{{ search_value }}" name="search_name">
<button type="submit">«</button>
</form>
and for the next link:
<form action="?page={{ page_obj.next_page_number }}" method="post">
{% csrf_token %}
<input type="hidden" value="{{ search_value }}" name="search_name">
<button type="submit">»</button>
</form>