Skip to content

Instantly share code, notes, and snippets.

@fandrefh
Created August 20, 2015 23:47
Show Gist options
  • Save fandrefh/7be31088d08f19d3e627 to your computer and use it in GitHub Desktop.
Save fandrefh/7be31088d08f19d3e627 to your computer and use it in GitHub Desktop.
def get_pacientes(request):
if request.is_ajax():
q = request.GET.get('term', '')
pacientes = Paciente.objects.filter(nome__icontains = q)[:20]
results = []
for paciente in pacientes:
paciente_json = {}
paciente_json = paciente.nome
results.append(paciente_json)
data = json.dumps(results)
else:
data = 'fail'
mimetype = 'application/json'
return HttpResponse(data, mimetype)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment