Skip to content

Instantly share code, notes, and snippets.

@andrelramos
Created March 14, 2016 17:26
Show Gist options
  • Select an option

  • Save andrelramos/0b5a28ee0462054d5a98 to your computer and use it in GitHub Desktop.

Select an option

Save andrelramos/0b5a28ee0462054d5a98 to your computer and use it in GitHub Desktop.
Exemplo de pesquisa AJAX (Controller)
@login_requerido(['administrador', 'auxiliar'], '/')
def consulta_cadastros(request):
form = forms.PesquisaCadastrosForm()
resposta = {}
if request.method == "POST":
form = forms.PesquisaCadastrosForm(request.POST)
if form.is_valid:
candidato = getCandidatoUsuario(request.user)
argumentos = functions.argumentosPesquisa(request)
resultado_pesquisa = models.Cadastro.objects.filter(candidato=candidato, **argumentos)
pesquisa_json = serializers.serialize('json', resultado_pesquisa, use_natural_foreign_keys=True)
return HttpResponse(pesquisa_json)
resposta['form'] = form
return render(request, 'consultas/cadastros.html', resposta)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment