diff options
| author | AK <andrei.avk@gmail.com> | 2018-03-24 12:45:09 -0400 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2018-03-26 12:41:30 -0400 |
| commit | 9fc5a1fa0c54843b4d98b1d93ccad4e0dc9b42e9 (patch) | |
| tree | c9a6412b06ed4624dd693234d17e22fd9a3c5b0f | |
| parent | 0118a2113d33353f15ed9b1e2d36ce81073f5110 (diff) | |
[2.0.x] Added a pagination example to ListView docs.
Backport of 3990d740180bc49a1479b8a2918b0878df65518a from master
| -rw-r--r-- | docs/ref/class-based-views/generic-display.txt | 5 | ||||
| -rw-r--r-- | docs/topics/pagination.txt | 5 |
2 files changed, 9 insertions, 1 deletions
diff --git a/docs/ref/class-based-views/generic-display.txt b/docs/ref/class-based-views/generic-display.txt index 8ebe871685..15d3351d48 100644 --- a/docs/ref/class-based-views/generic-display.txt +++ b/docs/ref/class-based-views/generic-display.txt @@ -115,6 +115,7 @@ many projects they are typically the most commonly used views. class ArticleListView(ListView): model = Article + paginate_by = 100 # if pagination is desired def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) @@ -144,6 +145,10 @@ many projects they are typically the most commonly used views. {% endfor %} </ul> + If you're using pagination, you can adapt the :ref:`example template from + the pagination docs <using-paginator-in-view>`. Change instances of + ``contacts`` in that example template to ``page_obj``. + .. class:: django.views.generic.list.BaseListView A base view for displaying a list of objects. It is not intended to be used diff --git a/docs/topics/pagination.txt b/docs/topics/pagination.txt index 81efaafd28..81b156cae6 100644 --- a/docs/topics/pagination.txt +++ b/docs/topics/pagination.txt @@ -74,6 +74,7 @@ page:: objects such as Django's ``QuerySet`` to use a more efficient ``count()`` method when available. +.. _using-paginator-in-view: Using ``Paginator`` in a view ============================== @@ -97,7 +98,9 @@ The view function looks like this:: return render(request, 'list.html', {'contacts': contacts}) In the template :file:`list.html`, you'll want to include navigation between -pages along with any interesting information from the objects themselves:: +pages along with any interesting information from the objects themselves: + +.. code-block:: html+django {% for contact in contacts %} {# Each "contact" is a Contact model object. #} |
