S
S
Sergey Nizhny Novgorod2016-09-19 14:50:18
Django
Sergey Nizhny Novgorod, 2016-09-19 14:50:18

How to make "compact" pagination in django?

Hello.
I ran into a situation that I had about 600 materials, and if I break them down 25 per page, we get 24 pages. And the pagination that is provided on the official django site gives us all 24 pages on the site.
Do not tell me how you can make this whole thing compact, so that let's say it displays the first three and the last page. And this bubble moved behind the pages?
So far in the template I use this thing:

<div class="row">
                        <div class="small-12 medium-12 large-12 column pagination_forum_block">
                            <ul class="pagination">
                                {% if forumpage.has_previous %}
                                    <li class="arrow"><a href="?page={{ forumpage.previous_page_number }}"><i class="fa fa-angle-double-left" aria-hidden="true"></i></a></li>
                                {% else %}
            {#                        <li class="arrow unavailable"><a href="">&laquo;</a></li>#}
                                {% endif %}

                                {% for page in forumpage.paginator.page_range %}
                                    {% if page == forumpage.number %}
                                        <li class="current"><a href="?page={{ page }}">{{ page }}</a></li>
                                    {% else %}
                                        <li><a href="?page={{ page }}">{{ page }}</a></li>
                                    {% endif %}
                                {% endfor %}

                                {% if forumpage.has_next %}
                                    <li class="arrow"><a href="?page={{ forumpage.next_page_number }}"><i class="fa fa-angle-double-right" aria-hidden="true"></i></a></li>
                                {% else %}
            {#                        <li class="arrow unavailable"><a href="">&raquo;</a></li>#}
                                {% endif %}
                            </ul>
                        </div>
                    </div>

And it turns out like this:
39bd50a2e5804ae29d24bf76e0bcb8f8.png
But I want something smarter and more compact, since the layout is adaptive and on small screens you get 3-4 rows of numbers.
----
After exploring many options (tag registration, plugins, custom solutions). Made according to the recommendation from this post: Adjusting pagination in django? - simple, banal and effective. Still easier and more efficient.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
aRegius, 2016-09-19
@Terras

Leave two sections:
Essentially:
if page.has_previous
page.number #active link
else
page.number
if page.has_next
page.paginator.num_pages #active link
else
page.paginator.num_pages
What will happen -something like (depending on design) " Previous ................... Next "

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question