Skip to content
Advertisement

Sorting and paginating object at the same time in django; after paginating the sort gets reset

If I have applied the sorting to my wallpapers and after that if I try to paginate the sorting gets reset. like if I have sorted wallpapers according to pub date in ascending order and after pagination, it gets back to normal.

view

JavaScript

Pagination code

JavaScript

JavaScript
JavaScript

Advertisement

Answer

The reason this happens is because you “drop” the URL parameters regarding sorting and searching. You should each time add these to the pagination URLs.

In the view you can make a querystring for all the parameters except page with:

JavaScript

then in the template, you render the links to the other pages with:

JavaScript

and this for all URL links.

Advertisement