Exemplo n.º 1
0
def edit_task(request, task_id):
    if request.method == "POST":
        task = TaskList.objects.get(pk=task_id)
        form = TaskForm(request.POST or None, instance=task)
        if form.is_valid():
            form.save()
        messages.success(request, "Task Edited!")
        return redirect('todolist')
    else:
        task_obj = TaskList.objects.get(pk=task_id)
        return render(request, 'edit.html', {'task_obj': task_obj})
Exemplo n.º 2
0
def edittask(request, id):
    if request.method == 'POST':
        task_obj = TaskList.objects.get(pk=id)
        form = TaskForm(
            request.POST or None, instance=task_obj
        )  #not creating new instance obj, utilizing already created so instance
        if form.is_valid:
            form.save()
        messages.success(request, ('Task edited!'))
        return redirect('todolist')
    else:
        task_obj = TaskList.objects.get(pk=id)
        return render(request, 'edit.html', {'task_obj': task_obj})
Exemplo n.º 3
0
def todolist(request):
    if request.method == "POST":
        form = TaskForm(request.POST or None)
        if form.is_valid():
            instance = form.save(commit=False)
            instance.manage = request.user
            instance.save()
        messages.success(request, "New Task Added!")
        return redirect('todolist')
    else:
        all_tasks = TaskList.objects.filter(manage=request.user)
        paginator = Paginator(all_tasks, 5)
        page = request.GET.get('pg')
        all_tasks = paginator.get_page(page)
        return render(request, 'todolist.html', {'all_tasks': all_tasks})
Exemplo n.º 4
0
def todolist(request):
    #context = {
    #    'todolisthome_welcome_text':'Welcome to Todo list',
    #}
    #return HttpResponse("Taskpage")
    #{} is context dict passed to template

    if request.method == 'POST':
        form = TaskForm(request.POST or None)
        if form.is_valid():
            form.save()
        messages.success(request, ('New task added!'))
        return redirect('todolist')
    else:  #for regular get request
        all_tasks = TaskList.objects.all()  #list of all tasks from models-db
        paginator = Paginator(
            all_tasks, 7
        )  #on which object pagination yo u want , no of recoudrds per page
        page = request.GET.get('pg')
        all_tasks = paginator.get_page(page)
        return render(request, 'todolisthome.html', {'all_tasks': all_tasks})