管理员将这些过滤器输出为带有<ul>s 内查询字符串的链接。您可以改为将其更改为选择。
那里使用的模板是admin/filter.html这样的:
{% load i18n %}
<h3>{% blocktrans with filter_title=title %} By {{ filter_title }} {% endblocktrans %}</h3>
<ul>
{% for choice in choices %}
<li{% if choice.selected %} class="selected"{% endif %}>
<a href="{{ choice.query_string|iriencode }}">{{ choice.display }}</a></li>
{% endfor %}
</ul>
您可以使用相同的名称提供自己的名称来覆盖他们的名称,因此重做可能是这样的:
{% load i18n %}
<h3>{% blocktrans with filter_title=title %} By {{ filter_title }} {% endblocktrans %}</h3>
<select>
{% for choice in choices %}
<option data-href="{{ choice.query_string|iriencode }}"
{% if choice.selected %} selected="selected"{% endif %}>
{{ choice.display }}
</option>
{% endfor %}
</select>
然后按照更改的过滤器链接进行操作:
$(function() {
$('select', '#changelist-filter').on('change', function(e) {
window.location = window.location.href + $(e.target).attr('data-href');
});
});
更进一步,您可以在之后使用Select2之类的东西来对待它们。