diff --git a/src/lists/views.py b/src/lists/views.py index f00b775..fe727ba 100644 --- a/src/lists/views.py +++ b/src/lists/views.py @@ -14,4 +14,9 @@ def view_list(request, list_id): def new_list(request): list_ = List.objects.create() Item.objects.create(text=request.POST['item_text'], list=list_) + 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}/') \ No newline at end of file diff --git a/src/superlists/urls.py b/src/superlists/urls.py index 8a35e64..f6d0f05 100644 --- a/src/superlists/urls.py +++ b/src/superlists/urls.py @@ -20,5 +20,5 @@ urlpatterns = [ url(r'^$', views.home_page, name='home'), url(r'^lists/new$', views.new_list, name='new_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'), ] \ No newline at end of file