1

I am working on a searchinput with additional parameters given through a django autocomplete light Select2Multiple widget.

class SearchParameterForm(forms.Form):
    p = forms.MultipleChoiceField(
        widget=autocomplete.Select2Multiple(url='search-parameter-autocomplete'),
        label='Search Parameter',
        required=False,
    )

&

class SearchParameterAutocomplete(LoginRequiredMixin, autocomplete.Select2ListView):
    def get_list(self):
        parameter_list = ['only stocked']
        for my_storage in Storage.objects.filter(workgroup=self.request.user.profile.workgroup).all():
            for workgroup in my_storage.workgroup.all():
                parameter_list.append(workgroup.name)
        return list(set(parameter_list))

I would like to set the initial value of the Widget depending on some parameters (e.g. self.request.user.profile.workgroup.name)

Setting the initial value of the field either directly in the class with some dummy values or in the view did not work. I would also like to store the selected values on page refresh.

initial = {"id": "AK2", "text": "AK2"}
initial = ['AK1']
initial = 'AK1'

Is there a way to do this with django or jquery?

~Fabian

PythonF
  • 456
  • 1
  • 5
  • 21

0 Answers0