예제 #1
0
def create_todo(request):
    form = TodoForm(request.POST)
    if form.is_valid():
        todo = Todo(title=form.cleaned_data['title'],
                    description=form.cleaned_data['description'],
                    is_done=False)
        todo.save()
        return redirect('todos index')
    return index(request, form)
예제 #2
0
def edit_todo(request, pk):
    todo = Todo.objects.get(pk=pk)
    if request.method == 'GET':
        form = TodoForm(instance=todo)
        return index(request, form, 'edit todo', pk=pk)
    else:
        form = TodoForm(request.POST)
        if form.is_valid():
            todo.title = form.cleaned_data['title']
            todo.description = form.cleaned_data['description']
            todo.save()
        return index(request, form)