I have the following code that only searches for the name of person, I can not think of how to search also by last name, here I leave the code to try to search by last name but it does not work does not search
views.py
def Buscarpersona(request):
if request.is_ajax():
search = request.GET.get('start', '')
#search2 = request.GET.get('start2', '')
personas = personalProfile.objects.filter(nombre__A_Paterno__icontains=search)
results = []
for pl in personas and apellido:
place_json ={
'titulo':pl.titulo,
'nombre':pl.nombre,
'A_Paterno':pl.A_Paterno,
'A_Materno':pl.A_Materno,
}
results.append(place_json)
data = json.dumps(results)
else:
data = 'fail'
mimetype = 'application/json'
return HttpResponse(data, mimetype)
Ajax
$(function() {
$("#id_user1").autocomplete({
minLenght: 4,
source: function(req, add){
var search=$("#id_user1").val();
$.ajax({
url:"{% url 'user:Buscarpersona' %}",
async:false,
dataType:'json',
type:'GET',
data:{'start':search},
success: function(data){
var suggestions=[];
$.each(data, function(index, objeto){
suggestions.push(objeto.titulo+""+ objeto.nombre +" "+ objeto.A_Paterno +" "+ objeto.A_Materno);
});
add(suggestions);
},
error:function(err){
alert("no existe el usuario");
}
});
}
});
});
I think I'm making a bad use of __icontains, correct me if I'm wrong