GitHub Commit - Episode 7

ListView is used for when we want to display a group of objects from a given model. In our example, we'll be displaying a list of blog articles on the blog home page.

ListView is where many people get lost, don't feel bad! The reason for this is because customization is more common with ListView than with the previous views, at least in my experience. To use pagination, you have to have a decent understanding of what's going on instead of just copy and pasting without knowing how to customize.

Important Class Methods

  • get_queryset - returns the queryset of all the objects to use for the ListView.
  • paginate_queryset - prepare the objects that should be on the page as well as page-specific data such as current page and total pages.
  • get_context_data - similar to DetailView, but also add context needed to display page data.