Beispiel #1
0
def turns_edit(request, id):
    turn_id = int(id)
    turn = Turn.objects.get(id=turn_id)

    if request.method == 'POST':
        form = TurnForm(request.POST, instance=turn)
        if form.is_valid():
            save = form.save()
            message = 'Turno Actualizado correctamente!'
            messages.add_message(request, messages.SUCCESS, message)
            return HttpResponseRedirect(reverse(turns_index))
    else:
        form = TurnForm(instance=turn)
    return render(request, 'turns/edit.html', {
        'form': form,
    })
Beispiel #2
0
def turns_new(request):
    if request.method == 'POST':
        form = TurnForm(request.POST.copy())
        form.instance.company_id = int(request.session['company_id'])

        if form.is_valid():
            save = form.save()

            message = 'Turno guardado!'
            messages.add_message(request, messages.SUCCESS, message)
            return HttpResponseRedirect(reverse(turns_index))
    else:
        form = TurnForm()
    return render(request, 'turns/new.html', {
        'form': form,
    })