-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathviews.py
30 lines (24 loc) · 866 Bytes
/
views.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
from django.shortcuts import render,redirect
from django.views.decorators.http import require_POST
from .models import List
from .forms import ListForm
def home(request):
todo_list=List.objects.order_by('id')
form=ListForm()
context={'todo_list' : todo_list,'form':form}
return render(request,'base.html',context)
@require_POST
def addTodo(request):
form=ListForm(request.POST)
if form.is_valid():
list=List(text=request.POST['text'])
return redirect('home')
def delete(request,list_id):
list=List.objects.get(pk=list_id)
list.delete()
return redirect('home')
def complete(request,list_id):
list=List.objects.get(pk=list_id)
list.completed=True
list.save()
return redirect('home')