Beispiel #1
0
def customers_new(request):
    if request.method == 'POST':
        form = CustomerForm(request.POST)
        if form.is_valid():
            save = form.save()
            message = 'Institucion guardado correctamente!'
            messages.add_message(request, messages.SUCCESS, message)
            return HttpResponseRedirect(reverse(customers_index))
    else:
        form = CustomerForm
    return render(request, 'customers/new.html', {
        'form': form,
    })
Beispiel #2
0
def customers_edit(request, id):
    customer_id = int(id)
    customer = Customer.objects.get(id=customer_id)
    if request.method == 'POST':
        form = CustomerForm(request.POST, request.FILES, instance=customer)
        if form.is_valid():
            save = form.save()
            message = 'Institucion actualizado correctamente!'
            messages.add_message(request, messages.SUCCESS, message)
            return HttpResponseRedirect(reverse(customers_index))
    else:
        form = CustomerForm(instance=customer)
    return render(request, 'customers/edit.html', {
        'form': form,
    })