如何在自定义Django管理表单中创建多个mutliple?

时间:2016-12-05 15:10:45

标签: django filter

我在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
          )

在界面中它返回列表(选择),我只能选择一个属性。但我需要实现多个选择。我发现,这个默认模板是 template / admin / 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>

也许我需要编写自己的模板,但不知道如何(我需要立即过滤所选的选项)。

1 个答案:

答案 0 :(得分:0)

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