Reputation:
Does anybody know where ModelSelect2MultipleField is imported from? I've been trying to import it into a file that I need, and I thought that I could do it with
from django_select2.fields import ModelSelect2MultipleField
but I keep getting errors. Before when I had it
from django_select2 import *
It said that ModelSelect2MultipleField, which I use in the py file, was not defined. Now it says that there is no module named fields.
The .py file I'm talking about can be found here (https://bitbucket.org/cbplusd/wibo/src/efc144e1bdc1eb52f76591c60ff0a1d40464b0ed/reports/forms.py?at=master&fileviewer=file-view-default).
The Django-Select2 I have installed is version 5.8.9, so is there another way to import ModelSelect2MultipleField other than this way?
Thanks in advance!
Upvotes: 0
Views: 1344
Reputation: 1559
You must initialise the form field as a Django widget and then specify the add-on widget in the parameters like so:
clients = ModelMultipleChoiceField(required=False, queryset=Contact.objects, widget=Select2MultipleWidget())
Upvotes: 0
Reputation: 1964
You need to use from django_select2.forms import ModelSelect2MultipleWidget
. I found this by looking at the test application here.
There is no ModelSelect2MultipleField there is however a ModelSelect2MultipleWidget which should do what you need.
Upvotes: 3