首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在自定义Django管理表单中创建多个选择?

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

Stack Overflow用户
提问于 2016-12-05 15:10:45
回答 1查看 160关注 0票数 0

我在django管理界面中有一个自定义过滤器

代码语言:javascript
复制
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
          )

在接口中,它返回list ( select ),我只能选择一个属性。但我需要实现多重选择。我发现,这个默认模板是template/admin/filter.html

代码语言:javascript
复制
{% 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>

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

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-12-08 10:03:56

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40977358

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档