7.11.2 The Last New View (w/ bug fix)

chap7-new
Jason Zhu 2020-11-11 15:27:37 +11:00
parent 84f6645fc1
commit d99dd167ac
2 changed files with 6 additions and 1 deletions

View File

@ -15,3 +15,8 @@ def new_list(request):
list_ = List.objects.create() list_ = List.objects.create()
Item.objects.create(text=request.POST['item_text'], list=list_) Item.objects.create(text=request.POST['item_text'], list=list_)
return redirect(f'/lists/{list_.id}/') 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}/')

View File

@ -20,5 +20,5 @@ urlpatterns = [
url(r'^$', views.home_page, name='home'), url(r'^$', views.home_page, name='home'),
url(r'^lists/new$', views.new_list, name='new_list'), url(r'^lists/new$', views.new_list, name='new_list'),
url(r'^lists/(\d+)/$', views.view_list, name='view_list'), url(r'^lists/(\d+)/$', views.view_list, name='view_list'),
url(r'^lists/(\d+)/add_item$', views.add_item, new='add_item'), url(r'^lists/(\d+)/add_item$', views.add_item, name='add_item'),
] ]