-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
db19359
commit 1510a4c
Showing
4 changed files
with
28 additions
and
2 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from django.forms import ModelForm | ||
from models import Task | ||
|
||
class TaskForm(ModelForm): | ||
class Meta: | ||
model = Task |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,22 @@ | ||
from django.shortcuts import render | ||
from todolist.models import Task | ||
from forms import TaskForm | ||
from django.core.exceptions import PermissionDenied | ||
|
||
def list(request): | ||
return render(request, 'todolist/list-view.html', { | ||
'tasks': Task.objects.all() | ||
if request.method == "GET": | ||
form = TaskForm() | ||
elif request.method == "POST": | ||
form = TaskForm(request.POST) | ||
if form.is_valid(): | ||
form.save() | ||
# make sure to return use a clean form for the resulting page | ||
form = TaskForm() | ||
|
||
else: | ||
raise PermissionDenied('Only GET and POST methods are allowed') | ||
|
||
return render(request, 'todolist/list-view.html', { | ||
'tasks': Task.objects.all(), | ||
'form': form | ||
}) |