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

Pagination does not carry filter parameters #45

Open
payton-yang opened this issue Mar 24, 2022 · 1 comment
Open

Pagination does not carry filter parameters #45

payton-yang opened this issue Mar 24, 2022 · 1 comment

Comments

@payton-yang
Copy link

payton-yang commented Mar 24, 2022

Describe the bug

Pagination does not carry filter parameters.

Steps to reproduce

  1. Input filter parameters
    http://127.0.0.1:8000/admin/reports/tpareports/?date_start=2012-09-26&date_end=2028-09-26

  2. Pagination is still original

image

Details

OS: Windows 10/Alpine Linux v3.13
Python version 3.6
Django version 3.1.3
django-admin-search version 0.3.11
Browser Chrome

Add

This plugin is great. I can't fix it because I'm a Django beginner.
I appreciate your contribution whether you fix this or not.

@bogdaniordachescu
Copy link

bogdaniordachescu commented May 24, 2023

Hi, just extend the pagination default from admin and drag allong tyhe params:

    @register.inclusion_tag("admin/pagination.html", takes_context=True)
    @register.tag
    def custom_pagination(context, cl):
        pagination = admin_list.pagination(cl)
    
        url = context.request.get_full_path()
        url_object = urlparse(url)
        queries = QueryDict(url_object.query, mutable=True)
        pagination['extra_params'] = queries.items()
        extra_param_url = ''
        for key, value in pagination['extra_params']:
            if key != 'p':
                extra_param_url += '&%s=%s' % (key, value)
        pagination['extra_param_url'] = extra_param_url
    
        return pagination

and override the admin pagination:

{% load admin_list %}
{% load i18n %}
{% load content_extras %}

<p class="paginator">
{% if pagination_required %}
    {% for i in page_range %}
        <a href="?p={{ i }}{{ extra_param_url }}">{{ i }}</a>
    {% endfor %}
{% endif %}
    {{ cl.result_count }} {% if cl.result_count == 1 %}{{ cl.opts.verbose_name }}{% else %}{{ cl.opts.verbose_name_plural }}{% endif %}
    {% if show_all_url %}<a href="{{ show_all_url }}" class="showall">{% trans 'Show all' %}</a>{% endif %}
    {% if cl.formset and cl.result_count %}<input type="submit" name="_save" class="default" value="{% trans 'Save' %}">{% endif %}
</p>

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

No branches or pull requests

2 participants