Managing paginated lists
If you have dynamically changing lists of objects or the amount of them is greater than 30, you will surely need pagination for the list. With pagination, instead of the full QuerySet
, you provide a fraction of the dataset that is limited to a specific amount per page and you will also show the links to get to the other pages of the list. Django has classes to manage the paginated data, and we will see how to do that in this recipe for the example provided in the previous recipe.
Getting ready
Let's start with the forms and views of the movies
app from the Filtering object lists recipe.
How to do it…
To add pagination to the list view of the movies, follow these steps:
- First, import the necessary pagination classes from Django. ...
Get Django: Web Development with Python now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.