2020-11-09 11:57:23 +11:00
|
|
|
from django.shortcuts import redirect, render
|
2020-10-15 17:43:46 +11:00
|
|
|
|
2020-11-09 11:16:18 +11:00
|
|
|
from lists.models import Item
|
|
|
|
|
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-09 11:16:18 +11:00
|
|
|
if request.method == 'POST':
|
2020-11-09 11:57:23 +11:00
|
|
|
Item.objects.create(text=request.POST['item_text'])
|
2020-11-10 23:56:56 +11:00
|
|
|
return redirect('/lists/the-only-list-in-the-world')
|
2020-11-09 11:16:18 +11:00
|
|
|
|
2020-11-09 12:22:55 +11:00
|
|
|
items = Item.objects.all() # get objects from database (model)
|
|
|
|
return render(request=request,
|
|
|
|
template_name='home.html',
|
2020-11-11 13:33:55 +11:00
|
|
|
context={'items': items}) # pass items into template using render
|
|
|
|
|
|
|
|
def view_list(request):
|
|
|
|
items = Item.objects.all()
|
|
|
|
return render(request, 'home.html', {'items': items})
|