How can I use FilteredSelectMultiple widget in a django custom form?

I'm trying to use Django's FilteredSelectMultiple widget in a custom form. This widget is used in the Django admin for fields like Permissions (e.g., http://127.0.0.1:8000/admin/auth/group/add/), where there are two boxes: one for available options and another for selected options.

enter image description here

However, when I try to use it, it only renders as a regular multi-select box.

That’s my current code:

View:

class SupervisorUpdateView(modal.BaseModalUpdateView):
    permission_required = 'management.change_supervisor'
    template_name = 'management/supervisors/update_supervisor.html'
    model = models.Supervisor
    form_class = forms.SupervisorForm
    success_message = 'Supervisor updated'

Form:

from django import forms
from django.contrib.admin.widgets import FilteredSelectMultiple

class SupervisorForm(BSModalModelForm):
    class Meta:
        model = models.Supervisor
        fields = '__all__'
        labels = {'supervisor': 'Supervisor', 'technicians': 'Technicians'}
        widgets = {
            'supervisor': forms.HiddenInput(),
            'technicians': FilteredSelectMultiple('Technicians', is_stacked=False),
        }

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.fields['technicians'].queryset = get_agparts_users()

Template:

{% extends 'core/_modal_form.html' %}
{% block header %}Update Supervisor{% endblock header %}
{% block button %}
    <button class="btn btn-primary submit-btn">Update</button>
{% endblock button %}

Despite this, the widget only renders as a basic multi-select dropdown without the dual-box UI. What am I missing? How can I properly use FilteredSelectMultiple outside of the Django admin?

Вернуться на верх