Django FilteredSelectMultiple没有在页面上呈现

时间:2022-05-28 02:58:34

I am currently using Django version 1.11.2 and would like to use the FilteredSelectMultiple widget outside of the admin page.

我目前正在使用Django版本1.11.2,并希望在管理页面之外使用filteredselectmultiwidget。

This is my forms.py:

这是我forms.py:

class TBDAuthGroupManageForm(forms.Form):
    permissions = forms.ModelMultipleChoiceField(queryset=Permission.objects.all(),
                                                required=True,
                                                widget=FilteredSelectMultiple("Permissions", is_stacked=False))

class Media:
    css = {'all': ('/static/admin/css/widgets.css',), }
    js = ('/admin/jsi18n/',)

def __init__(self, parents=None, *args, **kwargs):
    super(TBDAuthGroupManageForm, self).__init__(*args, **kwargs)

This is my views.py:

这是我views.py:

class TBDAuthGroupManageView(DetailView):
    model = TBDAuthGroup
    template_name = 'perms/tbdauthgroup_manage.html'

    def get_context_data(self, **kwargs):
    context = super(TBDAuthGroupManageView, self).get_context_data(**kwargs)
    context['form'] = TBDAuthGroupManageForm()
    return context

And this is my template:

这是我的模板:

{% extends "base.html" %}
{% load static %}
{% block css %}
    {{ form.media }}
    <script type="text/javascript" src="{% static 'js/jquery-3.1.1.min.js' %}"></script>
    <script type="text/javascript" src="/static/admin/js/jquery.min.js"></script>
    <script type="text/javascript" src="/static/admin/js/jquery.init.js"></script>
{% endblock %}
{% block content %}
    {{ form }}
{% endblock %}

However when I render it in the page, I only get this: Django FilteredSelectMultiple没有在页面上呈现

但是,当我在页面中呈现它时,我得到的是:

and not this:Django FilteredSelectMultiple没有在页面上呈现

而不是:

I would love to know what I'm doing wrong and how I could fix this so my form looks like the admin form.

我很想知道我做错了什么,以及如何修复它,使我的表单看起来像管理表单。

1 个解决方案

#1


1  

{% block content %}
{{ form.media }}
<form>
  {{ form.permissions }}
</form>
{% endblock %}

try this in your template

在模板中试试这个

#1


1  

{% block content %}
{{ form.media }}
<form>
  {{ form.permissions }}
</form>
{% endblock %}

try this in your template

在模板中试试这个