7.9.2 Adjusting the Rest of the World to Our New Models

chap7-new
Jason Zhu 2020-11-11 14:47:24 +11:00
parent db97326010
commit 6515ab1dc7
2 changed files with 6 additions and 10 deletions

View File

@ -8,10 +8,6 @@ class HomePageTest(TestCase):
response = self.client.get('/') response = self.client.get('/')
self.assertTemplateUsed(response, 'home.html') 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): class NewListTest(TestCase):
def test_can_save_a_POST_request(self): def test_can_save_a_POST_request(self):
@ -31,8 +27,9 @@ class ListViewTest(TestCase):
self.assertTemplateUsed(response=response, template_name='list.html') self.assertTemplateUsed(response=response, template_name='list.html')
def test_displays_all_items(self): def test_displays_all_items(self):
Item.objects.create(text="itemey 1") list_ = List.objects.create()
Item.objects.create(text="itemey 2") 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/') response = self.client.get('/lists/the-only-list-in-the-world/')

View File

@ -1,8 +1,6 @@
from typing import Text
from django.http import request
from django.shortcuts import redirect, render from django.shortcuts import redirect, render
from lists.models import Item from lists.models import Item, List
# Create your views here # Create your views here
def home_page(request): def home_page(request):
@ -13,5 +11,6 @@ def view_list(request):
return render(request, 'list.html', {'items': items}) return render(request, 'list.html', {'items': items})
def new_list(request): 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/') return redirect('/lists/the-only-list-in-the-world/')