2016-12-05 76 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。

相關問題