2019年10月14日月曜日

Django Admin画面 フィルタ一覧をドロップダウンメニューにする

How to change the Django admin filter to use a dropdown instead of list? - Stack Overflow
https://stackoverflow.com/questions/5429276/how-to-change-the-django-admin-filter-to-use-a-dropdown-instead-of-list

Install:

pip install django-admin-list-filter-dropdown

Enable in settings.py:

INSTALLED_APPS = (      ...      'django_admin_listfilter_dropdown',      ...  )

Use in admin.py:

from django_admin_listfilter_dropdown.filters import (      DropdownFilter, ChoiceDropdownFilter, RelatedDropdownFilter  )    class EntityAdmin(admin.ModelAdmin):      ...      list_filter = (          # for ordinary fields          ('a_charfield', DropdownFilter),          # for choice fields          ('a_choicefield', ChoiceDropdownFilter),          # for related fields          ('a_foreignkey_field', RelatedDropdownFilter),      )

Here's what it looks like:

Screenshot of dropdown list filter

0 件のコメント:

コメントを投稿