I would like to use django-autocomplete-light to autocomplete some fields from an external database that cannot be adjusted to conform to the DjangoORM requirements. Therefore I use SQL Alchemy to connect to this db.
I cannot find out how to do this. As an example I would like to make the autocomplete use the following instead of the Django Model for the table (Which doesn't work because there is a dual column primary key and no id field.
query = (session.query(TableA.FIRSTNAME).distinct(TableA.FIRSTNAME)
.filter(TableA.FIRSTNAME.match(name)))
data = query.limit(100).all()
Effectively I would like to make the field autocomplete the names from my above query. Instead of using the Django qs as shown in the documentation:
class CountryAutocomplete(autocomplete.Select2QuerySetView):
def get_queryset(self):
# Don't forget to filter out results depending on the visitor !
if not self.request.user.is_authenticated():
return Country.objects.none()
qs = Country.objects.all()
if self.q:
qs = qs.filter(name__istartswith=self.q)
return qs
class PersonForm(forms.ModelForm):
birth_country = forms.ModelChoiceField(
queryset=Country.objects.all(),
widget=autocomplete.ModelSelect2(url='country-autocomplete')
)