class InputFilter(admin.SimpleListFilter):
template = "admin/input_filter.html"
def lookups(self, request, model_admin):
# Dummy, required to show the filter.
return ((),)
def choices(self, changelist):
# Grab only the "all" option.
all_choice = next(super().choices(changelist))
all_choice["query_parts"] = (
(k, v)
for k, v in changelist.get_filters_params().items()
if k != self.parameter_name
)
yield all_choice
1条答案
按热度按时间aij0ehis1#
这里解释的东西会有帮助https://hakibenita.com/how-to-add-a-text-filter-to-django-admin
字符串
你需要重写模板
型
用法
型
https://gist.githubusercontent.com/hakib/1491a848e71078dae81fca48c46cc258/raw/19934611bcdd6d806aabaf00f55f582cd40fffd8/input_filter.html的
https://gist.githubusercontent.com/hakib/1491a848e71078dae81fca48c46cc258/raw/19934611bcdd6d806aabaf00f55f582cd40fffd8/admin.py的
所有信贷的主人这篇文章