2020-11-09 11:57:23 +11:00
|
|
|
from django.shortcuts import redirect, render
|
2020-10-15 17:43:46 +11:00
|
|
|
|
2020-11-11 14:47:24 +11:00
|
|
|
from lists.models import Item, List
|
2020-11-09 11:16:18 +11:00
|
|
|
|
2020-11-07 14:42:22 +11:00
|
|
|
# Create your views here
|
2020-11-07 15:23:42 +11:00
|
|
|
def home_page(request):
|
2020-11-11 14:19:55 +11:00
|
|
|
return render(request=request, template_name='home.html')
|
2020-11-11 13:33:55 +11:00
|
|
|
|
2020-11-11 14:54:17 +11:00
|
|
|
def view_list(request, list_id):
|
|
|
|
list_ = List.objects.get(id=list_id)
|
2020-11-11 15:47:02 +11:00
|
|
|
return render(request, 'list.html', {'list': list_})
|
2020-11-11 14:32:21 +11:00
|
|
|
|
|
|
|
def new_list(request):
|
2020-11-11 14:47:24 +11:00
|
|
|
list_ = List.objects.create()
|
|
|
|
Item.objects.create(text=request.POST['item_text'], list=list_)
|
2020-11-11 15:27:37 +11:00
|
|
|
return redirect(f'/lists/{list_.id}/')
|
|
|
|
|
|
|
|
def add_item(request, list_id):
|
|
|
|
list_ = List.objects.get(id=list_id)
|
|
|
|
Item.objects.create(text=request.POST['item_text'], list=list_)
|
2020-11-11 15:04:49 +11:00
|
|
|
return redirect(f'/lists/{list_.id}/')
|