--I want to place a button to clear all selected list_filters next to the list_filter title.
--Override "Change_list.html" of Template
--app configuration
C:Project Name
│ db.sqlite3
│ manage.py
│
├─.idea
│
├─Project Name
│ │ authentication.py
│ │ settings.py
│ │ urls.py
│ │ utils.py
│ │ wsgi.py
│ │ __init__.py
│ │
│ ├─locate
│ └─__pycache__
│
├─App Name
│ │ admin.py
│ │ apps.py
│ │ context_processors.py
│ │ forms.py
│ │ models.py
│ │ tests.py
│ │ urls.py
│ │ views.py
│ │ __init__.py
│ │
│ ├─locate
│ ├─migrations
│ │ └─__pycache__
│ ├─templatetags
│ │ │ mytag.py
│ │ │
│ │ └─__pycache__
│ │ mytag.cpython-37.pyc
│ │
│ └─__pycache__
│
├─templates
│ __init__.py
│
└─admin
│ base_site.html
│ index.html
│ __init__.py
│
└─App Name
│ change_form_help_text.html
│ change_list.html ← Add this file
│ __init__.py
│
├─model name1
│ change_form.html
│ __init__.py
│
└─model name2
change_form.html
__init__.py
Override as follows
Change_list.html
{% extends 'admin/change_list.html' %}
{% load admin_list %}
{% search_form cl %}
{% load i18n %}
{{ block.super }}
{% block filters %}
{% if cl.has_filters %}
<div id="changelist-filter">
<h2>{% trans 'Filter' %} <button id="clear" onclick="location.href=location.href.replace(/\#.*$/, '').replace(/\?.*$/, '');">clear</button></h2>
{% if cl.has_active_filters %}<h3 id="changelist-filter-clear">
<a href="{{ cl.clear_all_filters_qs }}">✖ {% trans "Clear all filters" %}</a>
</h3>{% endif %}
{% for spec in cl.filter_specs %}{% admin_list_filter cl spec %}{% endfor %}
</div>
{% endif %}
{% endblock %}
--The release of list_filter itself was realized by resetting the url that excludes the search query from the current url when the added button is clicked.
--If you know how to override Template, it's useful to modify the admin site a bit.
Recommended Posts