Exemplo n.º 1
0
def principal_new(request):
    if request.method == "POST":
        form = PrincipalForm(request.POST)
        if form.is_valid():
            principal = form.save(commit=False)
            principal.save()
            form.save_m2m()
            messages.success(
                request, 'A new principal record was successfully created.')
            return redirect('trip_new')
    else:
        form = PrincipalForm()
    return render(request, 'travel/principal_form.html', {'form': form})
Exemplo n.º 2
0
def principal_edit(request, pk):
    principal = get_object_or_404(Principal, pk=pk)
    if request.method == "POST":
        form = PrincipalForm(request.POST, instance=principal)
        if form.is_valid():
            principal = form.save(commit=False)
            principal.save()
            form.save_m2m()
            messages.success(request,
                             'The principal record was successfully updated.')
            return redirect('principal_detail', pk=principal.pk)
    else:
        form = PrincipalForm(instance=principal)
    return render(request, 'travel/principal_form.html', {
        'form': form,
        'principal': principal
    })
def principal_new(request):
    if request.method == "POST":
        form = PrincipalForm(request.POST)
        if form.is_valid():
            principal = form.save(commit=False)
            principal.save()
            form.save_m2m()
            messages.success(request, 'A new principal record was successfully created.')
            return redirect('trip_new')
    else:
        form = PrincipalForm()
    return render(request, 'travel/principal_form.html', {'form': form})
def principal_edit(request, pk):
    principal = get_object_or_404(Principal, pk=pk)
    if request.method == "POST":
        form = PrincipalForm(request.POST, instance=principal)
        if form.is_valid():
            principal = form.save(commit=False)
            principal.save()
            form.save_m2m()
            messages.success(request, 'The principal record was successfully updated.')
            return redirect('principal_detail', pk=principal.pk)
    else:
        form = PrincipalForm(instance=principal)
    return render(request, 'travel/principal_form.html', {'form': form, 'principal': principal})