2
我目前正在使用Django版本1.11.2,並且想要在管理頁面之外使用FilteredSelectMultiple小部件。Django FilteredSelectMultiple無法在頁面上呈現
這是我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)
這是我的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
這是我的模板:
{% 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 %}
我很想知道我做錯了,我怎麼能解決這個問題,所以我的形式看起來像管理形式。
這工作!謝謝! – DHerls