Exemplo n.º 1
0
def add(request):
    if request.method == 'POST':
        print('coucou')
        form = LicenseForm(request.POST)
        if form.is_valid():
            print('hey')
            form.save()
            return redirect('license')
    else:
        form = LicenseForm()

    return render(request, 'license/license_form.html', locals())
Exemplo n.º 2
0
def edit(request, pk=None):
    if pk is None:
        return redirect('add_license')
    elif request.method == 'POST':
        license = get_object_or_404(License, id=pk)
        form = LicenseForm(request.POST, instance=license)
        if form.is_valid():
            form.save()
            return redirect('license')
    else:
        edit = True  # The template know if we want to edit or to add a new license
        license = get_object_or_404(License, id=pk)
        form = LicenseForm(request.POST or None, instance=license)
        return render(request, 'license/license_form.html', locals())