예제 #1
0
def create(request):
    form = TodoForm(request.POST)
    if form.is_valid():
        form.save()
        return HttpResponseRedirect('/')
    else:
        return HttpResponseBadRequest()
예제 #2
0
def home(request):
    form = TodoForm()
    todos = Todo.objects.all()
    if request.method == 'POST':
        form = TodoForm(request.POST)
        if form.is_valid():
            form.save()
            return redirect('home')
    return render(request, 'core/home.html', {'form': form, 'todos': todos})
예제 #3
0
def update(request, todo_id):
    todo = Todo.objects.get(id=todo_id)
    form = TodoForm(instance=todo)
    if request.method == 'POST':
        form = TodoForm(request.POST, instance=todo)
        if form.is_valid():
            form.save()
            return redirect('home')
    return render(request, 'core/update.html', {'form': form, 'todo': todo})
예제 #4
0
def add(request, todolist_id):
    """
    View created to add a new Todo,
    Receiving an POST request and send it
    to the TodoForm, for beeing saved,
    if the form is valid.
    """
    todolist = get_object_or_404(TodoList, pk=todolist_id)
    todo_form = TodoForm(request.POST or None)

    if todo_form.is_valid():
        todo = todo_form.save(todolist=todolist)
        messages.success(request, u'Todo "%s" created with success.' % todo)
    else:
        messages.error(request, u'The form was not filled correctly.')

    return redirect('todos', todolist_id)
예제 #5
0
def add(request, todolist_id):
    """
    View created to add a new Todo,
    Receiving an POST request and send it
    to the TodoForm, for beeing saved,
    if the form is valid.
    """
    todolist = get_object_or_404(TodoList, pk=todolist_id)
    todo_form = TodoForm(request.POST or None)

    if todo_form.is_valid():
        todo = todo_form.save(todolist=todolist)
        messages.success(request, u'Todo "%s" created with success.' % todo)
    else:
        messages.error(request, u'The form was not filled correctly.')

    return redirect('todos', todolist_id)