0
我在Django管理界面如何在自定义Django管理员表单中创建多重选择?
class ClipExcludeRightsFilter(ListFilter):
title = 'rights'
parameter_name = 'exclude_rights'
template = 'admin_mod/filters/exclude_rights.html'
def lookups(self, request, model_admin):
result = (
('avod', 'avod'),
('svod', 'svod'),
('est', 'est'),
('tvod', 'tvod')
)
return result
def queryset(self, request, queryset):
if self.value():
urls_owner = ClipRestriction.objects.exclude(vod_system=self.value()).values_list('clip_id', flat=True)
return queryset.filter(
pk__in=urls_owner
)
自定义过滤器和接口,它返回列表(选择),我可以只选择一个属性。但我需要实现多选。我发现,这是默认的模板是模板/管理/ filter.html
{% load i18n %}
<h3>{% blocktrans with filter_title=title|capfirst %} By {{ filter_title }} {% endblocktrans %}</h3>
<select class="combobox">
{% for choice in choices %}
<option{% if choice.selected %} selected{% endif %} value="{{ choice.query_string|iriencode }}" >{{ choice.display }}</option>
{% endfor %}
</select>
也许我需要写我自己的模板,但不知道如何(我需要立即筛选出特定的选项)。
只有多对多关系支持乘法选择。 – marin