{{{
<!-- contacts is a instance of Page class -->
{% for p in contacts.paginator.page_range %}
<li>
<a href="{% url 'admin_user_index' %}?&page={{ p }}">
{{ p }}
</a>
</li>
{% endfor %}
}}}
But, when the pages is too more, for example 1000, Things are going to get
scary.
So, I suggest insert a method `part_page_range()` for class Page.
For example,
When the `contacts.paginator.num_pages` `=1000`,
and the `contacts.number` `=500`,
I can use the
{{{
contacts.part_page_range(5)
}}}
to acquire a range instance `range(498, 503)`.
I think Django will be more handy after insert this method.
--
Ticket URL: <https://code.djangoproject.com/ticket/29589>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* status: new => assigned
* owner: nobody => BobDu
* version: 2.0 => master
--
Ticket URL: <https://code.djangoproject.com/ticket/29589#comment:1>
Comment (by Tim Graham):
I'm not understanding the purpose of the new method. Can you demonstrate
example usage? The patch would also required tests and documentation.
--
Ticket URL: <https://code.djangoproject.com/ticket/29589#comment:2>
Comment (by Carlton Gibson):
The idea here is to generate a subset of page links for a navigation aid
right?
Something like (in HTML links):
{{{
1, 2, ... 498, 499, 500, 501, 502, 503, ... 9999, 1000
}}}
Rather than just outputting all 1000 links at once.
First question is, is this something we should add in core? (Maybe. Not
immediately sure what to say.)
But more, are there already community solutions that do this.
Django REST Framework provides utilities that do just this for the
pagination of it's Browsable API templates.
(See methods called from [https://github.com/encode/django-rest-
framework/blob/f404fda29c3c88e344db20f85cab7c51ef44ccdf/rest_framework/pagination.py#L255-L273
`PageNumberPagination.get_html_context()`].)
I imagine there will be other solutions also built around Django's
`Paginator`. Before doing anything in core it would be good to consider
what those are(?) (Even if that's only for implementation ideas.)
--
Ticket URL: <https://code.djangoproject.com/ticket/29589#comment:3>
Comment (by Tim Graham):
Solved by #25513?
--
Ticket URL: <https://code.djangoproject.com/ticket/29589#comment:4>
* status: assigned => closed
* resolution: => wontfix
Comment:
Discussion can continue but closing for now as it's not immediately
obvious to me that the proposed method is suitable.
--
Ticket URL: <https://code.djangoproject.com/ticket/29589#comment:5>
Comment (by BobDu):
Replying to [comment:4 Tim Graham]:
> Solved by #25513?
Yes, I saw that a similar feature was merged in #25513 to solve the
problem. Thanks the community’s support
--
Ticket URL: <https://code.djangoproject.com/ticket/29589#comment:6>
* resolution: wontfix => duplicate
--
Ticket URL: <https://code.djangoproject.com/ticket/29589#comment:7>