I am trying to code an autocomplete for django which would display multiple queryset instead of a single list, an example of another site that have this implementation can be found here: https://www.uala.it/
Now i was able to send in a queryset the objects of two model:
def multi_autocomplete(request):
if request.is_ajax():
# In base a cosa sta scrivendo l'utente mostro un set di aziende.
query = request.GET.get("term", "")
companies = Company.objects.filter(name__icontains=query)
treatments = Treatment.objects.filter(name__icontains=query)
results = []
for company in companies:
place_json = company.name
results.append(place_json)
for treatment in treatments:
place_json = treatment.name
results.append(place_json)
data = json.dumps(results)
return HttpResponse(data, "application/json")
As you can see i'm returning the json.dumps with the data from the two models, how can I change the ui to show the values in different columns like in the link i provided?