21 lines
680 B
Python
Raw Permalink Normal View History

2020-11-09 11:57:23 +11:00
from django.shortcuts import redirect, render
from lists.models import Item, List
2020-11-09 11:16:18 +11:00
# Create your views here
def home_page(request):
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)
return render(request, 'list.html', {'list': list_})
def new_list(request):
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_)
return redirect(f'/lists/{list_.id}/')