There is a form:
class CampaignLocationForm(forms.ModelForm): class Meta: model = CampaignLocation fields = ('location', 'location_type') widgets = { 'location': forms.Select( attrs={ 'class': 'form-control selectpicker', 'data-live-search': "true"} ), 'location_type': forms.Select( attrs={'class': 'form-control'} ) } There is a huge number of items in the location list More than 80,000. Therefore, I use Ajax-Bootstrap-Select for autocomplete. I don’t know how to set the queryset for the location field so that the initial value is empty or only the selected item is on the list (when changed)
In my view, it should look like this:
class CampaignLocationForm(forms.ModelForm): def __init__(self, *args, **kwargs): super(CampaignLocationForm, self).__init__(*args, **kwargs) if ***если location уже задан***: self.fields['location'].queryset = ??? else: self.fields['location'].choices = (('', ''),) What exactly should I check and what should the queryset be?