Example #1
0
def add(request):
    if request.method == 'POST': # If the form has been submitted...
        form = TaskForm(request.POST)
        if form.is_valid() : # All validation rules pass
            # Process the data in form.cleaned_data
            # ...
            Task = form.save(commit=False)
            Task.user = request.user
            Task.save()
            return HttpResponseRedirect('/listigain') # Redirect after POST
    else:
        form = TaskForm()

    return render(request, 'addtask.html', {
        'form': form,
        })
Example #2
0
def edit(request, task_id):
    task = get_object_or_404(Task, pk=task_id)
    if  request.user == task.user:
        if request.method == 'POST': # If the form has been submitted...
            form = TaskForm(request.POST, instance=task)
            if form.is_valid() : # All validation rules pass
                # Process the data in form.cleaned_data
                # ...
                form.save()
                return HttpResponseRedirect('/listigain') # Redirect after POST
        else:
            form = TaskForm(instance=task)

        return render(request, 'edittask.html', {
            'form': form,
            'task': task,
            })
    else:
        return HttpResponseRedirect('/listigain')