[PYTHON] I wanted to modify Django's admin site a bit

What I wanted to do

--I want to place a button to clear all selected list_filters next to the list_filter title. image.png

Method

--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 }}">&#10006; {% trans "Clear all filters" %}</a>
        </h3>{% endif %}
        {% for spec in cl.filter_specs %}{% admin_list_filter cl spec %}{% endfor %}
      </div>
    {% endif %}
  {% endblock %}

result

--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

I wanted to modify Django's admin site a bit
I compared Django's admin screens
I want to make a blog editor with django admin
I wrote a script to get a popular site in Japan
I made a C ++ learning site
I wanted to create a smart presentation with Jupyter Notebook + nbpresent
Hash chain I wanted to avoid (2)
I wanted to convert my face photo into a Yuyushiki style.
I wanted to evolve cGAN to ACGAN
I wanted to solve the ABC164 A ~ D problem with Python
[Django] I wanted to test when POSTing a large file [TDD]
Hash chain I wanted to avoid (1)
I wanted to generate a sentence like "Fucking Deca Rashomon" (past form)
I tried to create a linebot (implementation)
I want to print in a comprehension
I tried to create a linebot (preparation)
How to use ManyToManyField with Django's Admin
I wanted to solve ABC160 with Python
I want to build a Python environment
I wanted to solve ABC159 in Python
I made a script to display emoji
I tried to make a Web API
How to make a Pelican site map
I wanted to solve ABC172 with Python
I really wanted to copy with selenium
How to view images in Django's Admin
Implemented DQN in TensorFlow (I wanted to ...)
I want to make matplotlib a dark theme
I tried to build a super-resolution method / ESPCN
I want to easily create a Noise Model
Don't expect too much from Django's admin site
I want to INSERT a DataFrame into MSSQL
I tried to build a super-resolution method / SRCNN ①
I wanted to solve NOMURA Contest 2020 with Python
i-Town Page Scraping: I Wanted To Replace Wise-kun
I added a function to CPython (ternary operator)
I want to create a window in Python
I want to make a game with Python
I wanted to play with the Bezier curve
I wanted to install Python 3.4.3 with Homebrew + pyenv
I don't want to take a coding test
I created a Dockerfile for Django's development environment
I made a tool to compile Hy natively
I want to create a plug-in type implementation
I read "How to make a hacking lab"
I want to start over with Django's Migrate
I made a tool to get new articles
I want to easily find a delicious restaurant
I want to write to a file with Python
I tried to make a ○ ✕ game using TensorFlow
I just wanted to understand Python's Pickle module
I want to upload a Django app to heroku
[Python] I made a system to introduce "recipes I really want" from the recipe site!
I want to take a screenshot of the site on Docker using any font