shinneider / django-admin-inline-paginator

MIT License
128 stars 21 forks source link

support for grappelli #4

Open Safrone opened 3 years ago

Safrone commented 3 years ago

Love the project, it worked exactly how I needed and expected.

I use django-grappelli for an updated admin interface: https://github.com/sehmaschine/django-grappelli with that the styling on the paginated inlines don't look correct.

I was wondering if support for grappelli could be added to make using this seamless. I admit however I don't know how much is involved with that kind of change.

thanks!

Safrone commented 3 years ago

I was able to fix most of the styling issues by overriding the templates in case someone wants a quick fix:

templates/admin/tabular_paginated.html : copy templates/admin/edit_inline/tabular.html from grappelli and add {% include 'admin/tabular_paginator.html' %} at the end of the first div

<div>
    ...
    {% include 'admin/tabular_paginator.html' %}
</div>

templates/admin/tabular_paginator.html :

{% load i18n static %}

<div class="grp-module">
    <div class="grp-row">
        {% spaceless %}
            {% with inline_admin_formset.formset.page as page_obj %}
            <nav class="grp-pagination">
                <header style="display:none"><h1>Pagination</h1></header>
                <ul>
                    {% if page_obj.has_previous %}
                        <li><a href="?page={{ page_obj.previous_page_number }}">{% trans 'previous' %}</a></li>
                    {% endif %}
                    {% if page_obj.number|add:"-5" > 0 %}
                        <li><a class="btn-page page-available" href="?page=0">1</a></li>
                    {% endif %}
                    {% if page_obj.number|add:"-5" > 1 %}
                        <li class="grp-separator"><span>...</span></li>
                    {% endif %}
                    {% for page_num in page_obj.paginator.page_range %}
                        {% if page_obj.number == page_num %}
                            <li><span class="btn-page page-selected">{{ page_num }}</span></li>
                        {% else %}
                            {% if page_num > page_obj.number|add:"-5" and page_num < page_obj.number|add:"5" %}
                                <li><a class="btn-page page-available" href="?page={{ page_num }}">{{ page_num }}</a></li>
                            {% endif %}
                        {% endif %}
                    {% endfor %}

                    {% if page_obj.number|add:"5" < page_obj.paginator.num_pages %}
                        <li class="grp-separator"><span>...</span></li>
                    {% endif %}

                    {% if page_obj.number|add:"4" < page_obj.paginator.num_pages %}
                        <li><a class="btn-page page-available" href="?page={{ page_obj.paginator.num_pages }}">{{ page_obj.paginator.num_pages }}</a></li>
                    {% endif %}

                    {% if page_obj.has_next %}
                        <li><a href="?page={{ page_obj.next_page_number }}">{% trans 'next' %}</a></li>
                    {% endif %}
                    <li class="grp-results"><span class='btn-page results'>{{ page_obj.paginator.count }} Results</span></li>
                </ul>
            </nav>
            {% endwith %}
        {% endspaceless %}
    </div>
</div>

result: image

shinneider commented 3 years ago

Hello @Safrone, thanks for report this.

is not a bug of this lib, but your and another user request this change. maybe it's a valid point.

I've been thinking about the best way to do it... and start developing today, but i no have much time on this and next week...

however i create a PR in grappelli project, to facilitate this issue see PR.

I'll give you more news in the coming days.

Safrone commented 3 years ago

FYI this is how https://github.com/theatlantic/django-nested-admin handles this:

nested_admin.nested.NestedStackedInlineMixin:

class NestedStackedInlineMixin(NestedInlineModelAdminMixin):

    if 'grappelli' in settings.INSTALLED_APPS:
        template = 'nesting/admin/inlines/grappelli_stacked.html'
    else:
        template = 'nesting/admin/inlines/stacked.html'

class NestedStackedInline(NestedStackedInlineMixin, InlineModelAdmin):
    pass
shinneider commented 3 years ago

@Safrone sorry for the long time to response.

I started de branch to support, and i testing it. now, wait de grappelli repo owner approv my PR, and finish all tests on my machine