S
S
SexyHair2020-01-15 18:56:32
Django
SexyHair, 2020-01-15 18:56:32

How to create an autocomplete field with django-autocomplete-light?

Can't create autocomplete field (python3.8, django3.0)
Here is view/urlpatterns/widget on form

class ProgrammingLanguageAutocompleteView(autocomplete.Select2QuerySetView):
    def get_queryset(self):
        if self.q:
            qs = ProgrammingLanguage.objects.filter(value__istartswith=self.q)[:10]
        else:
            qs = ProgrammingLanguage.objects.all()
        return qs

path(
    'programming-language-autocomplete',
    ProgrammingLanguageAutocompleteView.as_view(), 
    name='programming_language_autocomplete'
),

widgets = {
    'programming_language': autocomplete.ModelSelect2(url='programming_language_autocomplete')
}

When going to /programming-language-autocomplete?q=Py, everything finds
{"results": [{"id": "13298", "text": "Python", "selected_text": "Python"}], "pagination": {"more": false}}

And the field on the page in the form is generated empty, without the possibility of entering text
5e1f3535731e5727236177.png
In INSTALLED_APPS 'dal' and 'dal_select2' come before django.contrib.admin

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question