from django.db import models from django.contrib.auth.models import User from django.http import * from django.shortcuts import * from django.core.context_processors import csrf from django.views.decorators.csrf import csrf_exempt import json from snct.models import cat_personas @csrf_exempt def ajaxautocompletable(request): print ("entro") if request.is_ajax(): print ("entro") q = request.GET.get('term', '') drugs = cat_personas.objects.filter(nombre__icontains = q )[:5] results = [] for drug in drugs: drug_json = {} drug_json['id'] = drug.id drug_json['label'] = drug.nombre drug_json['value'] = drug.nombre results.append(drug_json) data = json.dumps(results) else: data = 'fail' mimetype = 'application/json' return HttpResponse(data, mimetype)