because we’re not passing
list
into the template. It actually gives us an opportunity to
simplify a little:
lists/views.py.
def
view_list
(
request
,
list_id
):
list_
=
List
.
objects
.
get
(
id
=
list_id
)
return
render
(
request
,
'list.html'
, {
'list'
:
list_
})
That, of course, will break because the template is expecting
items
:
AssertionError: False is not true : Couldn't find 'itemey 1' in response
But we can fix it in
list.html
, as well as adjusting the form’s POST action:
lists/templates/list.html (ch06l043).
<form
method=
"POST"
action=
"/lists/{{ list.id }}/add_item"
>
[...]
{% for item in list.item_set.all %}
<tr><td>
{{ forloop.counter }}: {{ item.text }}
</td></tr>
{% endfor %}
.item_set
is called a “reverse lookup”—it’s one of Django’s incredibly useful bits of
ORM that lets you look up an object’s related items from a different table…
So that gets the unit tests to pass:
Ran 10 tests in 0.060s
OK
How about the FT?
$
python3 manage.py test functional_tests
Creating test database for alias 'default'...
.
---------------------------------------------------------------------
Ran 1 test in 5.824s
OK
Destroying test database for alias 'default'...
Yes! And a quick check on our to-do list:
One More View to Handle Adding Items to an Existing List
|
109