diff --git a/src/lists/templates/list.html b/src/lists/templates/list.html
index ca484f0..f27d3bb 100644
--- a/src/lists/templates/list.html
+++ b/src/lists/templates/list.html
@@ -4,13 +4,13 @@
Your To-Do list
-
- {% for item in items %}
+ {% for item in list.item_set.all %}
{{ forloop.counter }}: {{ item.text }} |
{% endfor %}
diff --git a/src/lists/tests.py b/src/lists/tests.py
index 56bfe48..003d618 100644
--- a/src/lists/tests.py
+++ b/src/lists/tests.py
@@ -1,3 +1,4 @@
+from django.http import response
from django.test import TestCase
from lists.models import Item, List
@@ -65,7 +66,6 @@ class ListViewTest(TestCase):
Item.objects.create(text="other list item 1", list=other_list)
Item.objects.create(text="other list item 2", list=other_list)
-
response = self.client.get(f'/lists/{correct_list.id}/')
self.assertContains(response, 'itemey 1')
@@ -73,6 +73,12 @@ class ListViewTest(TestCase):
self.assertNotContains(response=response, text='other list item 1')
self.assertNotContains(response=response, text='other list item 2')
+ def test_passes_correct_list_to_template(self):
+ other_list = List.objects.create()
+ correct_list = List.objects.create()
+ response = self.client.get(f'/lists/{correct_list.id}/')
+ self.assertEqual(response.context['list'], correct_list)
+
class ListAndItemModelsTest(TestCase):
def test_saving_and_retrieving_items(self):
diff --git a/src/lists/views.py b/src/lists/views.py
index fe727ba..f357537 100644
--- a/src/lists/views.py
+++ b/src/lists/views.py
@@ -8,8 +8,7 @@ def home_page(request):
def view_list(request, list_id):
list_ = List.objects.get(id=list_id)
- items = Item.objects.filter(list=list_)
- return render(request, 'list.html', {'items': items})
+ return render(request, 'list.html', {'list': list_})
def new_list(request):
list_ = List.objects.create()