My problem is that I'm using an autocomplete to relate a model in Django 1.11. Until now that autocomplete is looking for me, but I want the result to keep it in an input. That autocomplete I'm using it in a registry. I hope and help me.
Vista
def Autocomplete1(request):
if request.is_ajax:
search=request.GET.get('start','')
doctores=Solicitante.objects.filter(nombre__icontains=search)
results=[]
for doctor in doctores:
doctor_json={}
doctor_json['label']=doctor.nombre+" "+doctor.apellido
doctor_json['value']=doctor.nombre+" "+doctor.apellido
results.append(doctor_json)
data_json=json.dumps(results)
else:
data_json='fail'
mimetype="application/json"
return HttpResponse(data_json,mimetype)
Javascript Function
$("#tags5").autocomplete({
minLength:2,
source: function(req, add){
var search=$("#tags5").val();
$.ajax({
url:'/registro/autocomplete1/',
async:false,
dataType:'json',
type:'GET',
data:{ 'start': search,},
success: function(data){
var suggestions=[];
$.each(data, function(index, objeto){
suggestions.push(objeto);
});
add(suggestions);
},
error:function(err){
alert("error");
}
});
}
});
The input of the Form
<div class="form-group">
<div class="ui-widget">
<label for="tags5">Ajax con GET: </label>
<input id="tags5" name="relacion">
</div>
</div>