Django FilteredSelectMultiple not rendering on page

自作多情 提交于 2019-12-12 18:14:09

问题


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

This is my 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:

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:

and not this:

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:


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

try this in your template



来源:https://stackoverflow.com/questions/44644521/django-filteredselectmultiple-not-rendering-on-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!