2016-12-05 86 views
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> 

也许我需要写我自己的模板,但不知道如何(我需要立即筛选出特定的选项)。

+0

只有多对多关系支持乘法选择。 – marin

回答

0

我刚刚选择了所有选项:使用jquery进行选择,然后将其作为参数传递给我的url。