Esempio n. 1
0
def cliente_edit(request, pk):
    cliente = get_object_or_404(Cliente, pk=pk)
    if request.method == "POST":
        form = ClienteForm(request.POST, instance=cliente)
        if form.is_valid():
            cliente = form.save(commit=False)
            cliente.save()
            messages.success(request, UPDATE_MSG)
            return HttpResponseRedirect(r('cliente'))
    else:
        form = ClienteForm(instance=cliente)

    context = {'label': 'Editar', 'form': form}
    return render(request, 'cliente/clientes.html', context)
Esempio n. 2
0
def cliente_new(request):
    context = {'label': 'Cadastrar', 'form': ClienteForm()}

    if request.method == 'GET':
        return render(request, 'cliente/clientes.html', context)

    form = ClienteForm(request.POST)
    context['form'] = form

    if not form.is_valid():
        return render(request, 'cliente/clientes.html', context)

    form.save()

    messages.success(request, SUCCESS_MSG)
    return HttpResponseRedirect(r('cliente'))