redefined & added arguments to existing FBVs in apps.dashboard.views; added new FBV to add to-do items to existing lists; added capture groups to some paths in .urls (tho these are now due for DRY refactor); django templating added to form action in templates/apps/dashboard/list.html; DashViewTest(), NewListTest() & NewItemTest() refactored for dynamic ids in .tests
This commit is contained in:
@@ -4,11 +4,18 @@ from .models import Item, List
|
||||
def home_page(request):
|
||||
return render(request, 'apps/dashboard/home.html')
|
||||
|
||||
def view_list(request):
|
||||
items = Item.objects.all()
|
||||
return render(request, 'apps/dashboard/list.html', {'items': items})
|
||||
def view_list(request, list_id):
|
||||
our_list = List.objects.get(id=list_id)
|
||||
items = Item.objects.filter(list=our_list)
|
||||
return render(request, 'apps/dashboard/list.html', {'items': items, 'list': our_list})
|
||||
|
||||
def new_list(request):
|
||||
nulist = List.objects.create()
|
||||
Item.objects.create(text=request.POST['item_text'], list=nulist)
|
||||
return redirect('/apps/dashboard/the-only-list-in-the-world/')
|
||||
return redirect(f'/apps/dashboard/{nulist.id}/')
|
||||
|
||||
def add_item(request, list_id):
|
||||
our_list = List.objects.get(id=list_id)
|
||||
Item.objects.create(text=request.POST['item_text'], list=our_list)
|
||||
return redirect(f'/apps/dashboard/{our_list.id}/')
|
||||
|
||||
|
||||
Reference in New Issue
Block a user