[Python] Django FilteredSelectMultiple not rendering on page

Discussão em 'Python' iniciado por Stack, Março 11, 2025.

  1. Stack

    Stack Membro Participativo

    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:

    [​IMG]

    and not this:

    [​IMG]

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

    Continue reading...

Compartilhe esta Página