Django Autocomplete Light not working with Django update from Django 3.1 to 4.1
The application I inherited was at Django 2.2. I have gradually updated to 4.1 and everything works except the Django Autocomplete Light fields. For some forms.ModelForm, I have a box with a correct list that can be selected but it does not have the ability to type the first few letters and select from that filtered list. Most of the autocomplete fields are on forms.Form and either display a dropdown box where the only choice is '-----', a scroll bar only with no list, or a box that is 2 x 47 pixels.
I have gone through the DAL documentation but could not find a solution. I have searched here plus other Google searches but I have not found a solution.
I do realize that parts of the code use the older URL pattern that includes ^, $, and ?P< items. I have tried to change these for one of the apps but it did not solve the issue.
forms.py
# Forms
from django import forms
from django.forms import ModelForm
# Models
from login.models import User
from .models import Suggestion, SuggestionDecision, Implementation
# Autocomplete
from dal import autocomplete
class ReviewForm(forms.ModelForm):
class Meta:
model = Suggestion
fields = ['suggestion', 'supervisors', 'managers']
widgets = {
'supervisors': autocomplete.ModelSelect2Multiple(url='login:user_autocomplete'),
'managers': autocomplete.ModelSelect2Multiple(url='login:user_autocomplete')
}
urls.py
from django.urls import path, re_path
from process_improvement import views as pi_views
app_name='process_improvement'
re_path(r'^autocomplete/suggestion/$', pi_views.SuggestionAutocomplete.as_view(), name='suggestion_autocomplete')
views.py
from dal import autocomplete
from django.urls import reverse
from django.shortcuts import redirect
from django.contrib.auth.mixins import LoginRequiredMixin
class SuggestionAutocomplete(autocomplete.Select2QuerySetView, LoginRequiredMixin):
def get_queryset(self):
qs = Suggestion.objects.all()
if self.q:
for term in self.q.split():
qs = qs.filter(Q(suggestion__icontains=term) | Q(pk__icontains=term) | Q(created_at__icontains=term))
return qs
suggestion.html
<form method="POST" class="needs-validation" id="suggestionForm" data-parsley-validate>
{% csrf_token %}
<label for="id_supervisors">Supervisors*</label>
{{ suggestionForm.supervisors }}
{{ suggestionForm.suggestion | as_crispy_field }}
</form>
This is the code for the fields that appear with a list that can be selected but not the option to enter the first few letters of the name. What do I need to change to get this working properly?