Ejemplo n.º 1
0
def new_task(request):
    if request.method == "POST":
        form = TaskForm(request.POST)
        if form.is_valid():
            task = form.save()
            task.save()
            return HttpResponseRedirect("/list/")
    else:
        form = TaskForm()
    return render(request, 'create_task.html', {'form': form})
Ejemplo n.º 2
0
def update_task(request, pk=None):
    try:
        task = Task.objects.get(id=pk)
    except:
        return HttpResponseRedirect("/")
    if request.method == "POST":
        form = TaskForm(request.POST, instance=task)
        if form.is_valid():
            task = form.save()
            task.save()
            return HttpResponseRedirect("/list/")
    elif pk is not None:
        form = TaskForm(instance=task)
        return render(request, 'create_task.html', {'form': form})