Hello everyone i recently made a autocomplete which is based on my database, the problem is i think it requires a bit of improvement. For example: If a user inputs twice the same value twice, the autocomplete also recommends the same values twice, there is also the problem of escalation i am pretty sure this code might be bad for when my application database size increases. Would love some ideas on how to fix those issues or some good alternatives. Here is the autocomplete view
@login_required
def AutocompleteModelo(request):
if 'term' in request.GET:
query=DataDB.objects.filter(modelo__istartswith=request.GET.get('term'))
modelos=list()
for q in query:
modelos.append(q.modelo)
return JsonResponse(modelos, safe=False)
return render(request,'data.insiradado.html')
And here it is the jquery script for the autocomplete.
<script>
$(function () {
$("#modelo").autocomplete({
source: '{% url 'data-AutocompleteModelo' %}',
minLength: 1
});
});
</script>
Btw modelo is the name of the db column, thanks for the help.