Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support for grappelli #4

Open
Safrone opened this issue Feb 1, 2021 · 4 comments
Open

support for grappelli #4

Safrone opened this issue Feb 1, 2021 · 4 comments
Labels
enhancement New feature or request

Comments

@Safrone
Copy link

Safrone commented Feb 1, 2021

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
Copy link
Author

Safrone commented Feb 1, 2021

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
Copy link
Owner

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
Copy link
Author

Safrone commented Mar 4, 2021

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 added a commit that referenced this issue Mar 22, 2021
@shinneider
Copy link
Owner

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants