django-admin-numeric-filter icon indicating copy to clipboard operation
django-admin-numeric-filter copied to clipboard

Storing State of Collapsed Filters

Open srkunze opened this issue 1 year ago • 0 comments

Thanks for this project. I recently integrated these filter types and found that they currently don't match the style of Django 2.4.1.

I overrode the template filter_numeric_range.html with the following source:

{% load i18n %}

{% with choices.0 as choice %}
<details open>
    <summary>{% blocktrans with filter_title=title %} By {{ filter_title }}{% endblocktrans %} </summary>
    <form method="get" class="admin-numeric-filter-wrapper">
        {% for k, v in choice.request.GET.items %}
            {% if not k == choice.parameter_name|add:'_from' and not k == choice.parameter_name|add:'_to' %}
                <input type="hidden" name="{{ k }}" value="{{ v }}">
            {% endif %}
        {% endfor %}

        <div class="admin-numeric-filter-wrapper-group">
            {{ choice.form.as_p }}
        </div><!-- /.filter-numeric-filter-wrapper-group -->

        <button type="submit" class="submit">{% trans 'Apply' %}</button>
    </form>
</details>
{% endwith %}

As you can see the "summary" and "details" elements are present. Mind the spaces before/after the summary text content.

Unfortunately, collapsing works but restoring after a reload not.

I think this would be a valuable addition to this plugin.

srkunze avatar May 24 '23 12:05 srkunze