Django FilteredSelectMultiple not rendering on page
Asked Answered
R

1

3

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:

field not rendering properly

and not this:

expected field rendering

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

Residential answered 20/6, 2017 at 5:29 Comment(0)
B
5
{% block content %}
{{ form.media }}
<form>
  {{ form.permissions }}
</form>
{% endblock %}

try this in your template

Bullish answered 20/6, 2017 at 6:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.