I'm fairly new to Class Based Views and I have a problem.
I implemented get_queryset to return all my users (for testing) and they are returned and pagination works fine (outside get_queryset, I do have "paginate_by" field set).
A user can then search some specific users via POST and the end of post method is:
return render(request, self.template_name, {'objects': some_users})
It works fine, but pagination is lost. What am I doing wrong?
The pagination is done in
paginate_queryset
, called byget_context_data
, called bypost
(that defaults to a subcall toget
) , so you can so something like (given you have a filter method that filters based on post data):the parent post will call
get_queryset
, that returns your filteredself.queryset
, and it will paginate it when callingget_context_data
to not display the queryset on the first
get
,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
,
and for the next link: