From 6515ab1dc7e2ad376513b5a4a3c43038522f0274 Mon Sep 17 00:00:00 2001 From: JasonHomeWorkstationUbuntu Date: Wed, 11 Nov 2020 14:47:24 +1100 Subject: [PATCH] 7.9.2 Adjusting the Rest of the World to Our New Models --- src/lists/tests.py | 9 +++------ src/lists/views.py | 7 +++---- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/src/lists/tests.py b/src/lists/tests.py index d3fa49c..828f6fe 100644 --- a/src/lists/tests.py +++ b/src/lists/tests.py @@ -8,10 +8,6 @@ class HomePageTest(TestCase): response = self.client.get('/') self.assertTemplateUsed(response, 'home.html') - def test_only_saves_items_when_necessary(self): - self.client.get('/') - self.assertEqual(Item.objects.count(), 0) - class NewListTest(TestCase): def test_can_save_a_POST_request(self): @@ -31,8 +27,9 @@ class ListViewTest(TestCase): self.assertTemplateUsed(response=response, template_name='list.html') def test_displays_all_items(self): - Item.objects.create(text="itemey 1") - Item.objects.create(text="itemey 2") + list_ = List.objects.create() + Item.objects.create(text="itemey 1", list=list_) + Item.objects.create(text="itemey 2", list=list_) response = self.client.get('/lists/the-only-list-in-the-world/') diff --git a/src/lists/views.py b/src/lists/views.py index 7aa1cc9..77cc557 100644 --- a/src/lists/views.py +++ b/src/lists/views.py @@ -1,8 +1,6 @@ -from typing import Text -from django.http import request from django.shortcuts import redirect, render -from lists.models import Item +from lists.models import Item, List # Create your views here def home_page(request): @@ -13,5 +11,6 @@ def view_list(request): return render(request, 'list.html', {'items': items}) def new_list(request): - Item.objects.create(text=request.POST['item_text']) + list_ = List.objects.create() + Item.objects.create(text=request.POST['item_text'], list=list_) return redirect('/lists/the-only-list-in-the-world/') \ No newline at end of file