Exemple #1
0
def veiculo_edit(request, pk):
    veiculo = get_object_or_404(Veiculo, pk=pk)
    if request.method == "POST":
        form = VeiculoForm(request.POST, instance=veiculo)
        if form.is_valid():
            veiculo = form.save(commit=False)
            veiculo.save()
            messages.success(request, UPDATE_MSG)
            return HttpResponseRedirect(r('veiculo'))
    else:
        form = VeiculoForm(instance=veiculo)

    context = {'label': 'Editar', 'form': form}
    return render(request, 'veiculo/veiculos.html', context)
Exemple #2
0
def veiculo_new(request):
    context = {'label': 'Cadastrar', 'form': VeiculoForm()}

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

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

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

    form.save()

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