•
Get FTs to clean up after themselves
•
Adjust model so that items are associated
with different lists
•
Add unique URLs for each list
•
Add a URL for creating a new list via POST
•
Add URLs for adding a new item to an
existing list via POST
Adjusting Our Models
Enough housekeeping with our URLs. It’s time to bite the bullet and change our models.
Let’s adjust the model unit test. Just for a change, I’ll present the changes in the form of
a diff:
lists/tests.py.
@@ -3,7 +3,7 @@ from django.http import HttpRequest
from django.template.loader import render_to_string
from django.test import TestCase
-from lists.models import Item
+from lists.models import Item, List
from lists.views import home_page
class HomePageTest(TestCase):
@@ -60,22 +60,32 @@ class ListViewTest(TestCase):
-class ItemModelTest(TestCase):
+class ListAndItemModelsTest(TestCase):
def test_saving_and_retrieving_items(self):
+ list_ = List()
+ list_.save()
+
first_item = Item()
first_item.text = 'The first (ever) list item'
+ first_item.list = list_
first_item.save()
second_item = Item()
second_item.text = 'Item the second'
+ second_item.list = list_
second_item.save()
Adjusting Our Models
|
97