项目
在 GitHub 查看
mrts/django-admin-list-filter-dropdown
关于
Use dropdowns in Django admin list filter
网站与应用开发实测星标增长
- 24小时
- 0
- 7天
- 0
- 15天
- 0
- 1个月
- 正在收集历史
各周期内的星标净变化,周期相互重叠,并非每日新增。缺失的测量保持空白。星标代表关注度,不代表软件质量。
README.md
原文django-admin-list-filter-dropdown
A Django admin filter implementation that renders as a dropdown.
If you have more than ten values for a field that you want to filter by in Django admin, the filtering sidebar gets long, cluttered and hard to use.
This app contains the DropdownFilter class that renders as a drop-down in the
filtering sidebar to avoid this problem.
Usage
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, RelatedDropdownFilter, ChoiceDropdownFilter
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),
)
Example of a custom filter that uses the provided template:
class CustomFilter(SimpleListFilter):
template = 'django_admin_listfilter_dropdown/dropdown_filter.html'
def lookups(self, request, model_admin):
...
def queryset(self, request, queryset):
...
Example
Here's what it looks like:

Credits
Based on this StackOverflow question and code from FeinCMS.
探索相关项目
加载中…