I guess most of you have paid attention to the admin site's multiple choice field:
I want the exact same widget to my MultipleChoiceField in my form. How is it possible to use that widget?
I guess most of you have paid attention to the admin site's multiple choice field:
I want the exact same widget to my MultipleChoiceField in my form. How is it possible to use that widget?
You can use the FilteredSelectMultiple, for example writing a field into admin form
from django import forms
from django.contrib.admin import widgets
class SomeAdminForm(forms.ModelForm):
some_field = forms.ModelMultipleChoiceField(
widget=widgets.FilteredSelectMultiple('Field name', False)
queryset=SomeModel.objects.all()
)
class Meta:
model = YourModel
fields = ['your_model_fields', 'some_field']
It's works for forms.MultipleChoiceField.
The Django admin makes all the magic.