new and refined tests for dashboard app; home iterates list w. django templating; views refined for redirect after post request

This commit is contained in:
Disco DeDisco
2025-12-31 14:39:26 -05:00
parent 1950eaa12e
commit c318a526fc
3 changed files with 30 additions and 17 deletions

View File

@@ -1,14 +1,10 @@
from django.http import HttpResponse
from django.shortcuts import render
from django.shortcuts import redirect, render
from .models import Item
def home_page(request):
item = Item()
item.text = request.POST.get('item_text', '')
item.save()
if request.method == 'POST':
Item.objects.create(text=request.POST['item_text'])
return redirect('/')
return render(
request,
'apps/dashboard/home.html',
{'new_item_text': request.POST.get('item_text', '')},
)
items = Item.objects.all()
return render(request, 'apps/dashboard/home.html', {'items': items})