generated from TH-Activities/saturday-hack-night-template
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathviews.py
38 lines (27 loc) · 852 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
31
32
33
34
35
36
37
38
from django.shortcuts import render, redirect
from django.contrib import messages
# import todo form and models
from .forms import TodoForm
from .models import Todo
###############################################
def index(request):
item_list = Todo.objects.order_by("-date")
if request.method == "POST":
form = TodoForm(request.POST)
if form.is_valid():
form.save()
return redirect('todo')
form = TodoForm()
page = {
"forms": form,
"list": item_list,
"title": "TODO LIST",
}
return render(request, 'todo/index.html', page)
### function to remove item, it receive todo item_id as primary key from url ##
def remove(request, item_id):
item = Todo.objects.get(id=item_id)
item.delete()
messages.info(request, "item removed !!!")
return redirect('todo')
# Create your views here.