David J Nevin+= Code

Last updated: Sep 15, 2022

Django Individual Item Page

Next step is to setup an individual item page. This tutorial is giving me a some good insights into the Critique Wheel rewrite. Ideas are percolating, and questions about testing and deploying are scratching at the back of my neck. Patience.

Individual Item Page

First step with a new page, add it to the app’s views.py.

100
101
102
103
def detail(request, detail_id):
    detail = Listings.objects.get(id=detail_id)
    context = {'detail': detail}
    return render(request, 'listings/detail.html', context)

Note to self: context is a dictionary of values passed to the template.

The urls.py additional line is:

100
path('my_listings/', views.my_listings, name='my_listings')

And the template key part:

100
101
102
103
104
105
106
107
108
109
for my_listing in my_listings %}
<tr>
	<td>{{ my_listing.title }}</td>
	<td>{{ my_listing.list_date }}</td>
	<td><a class="btn" href="{% url 'listings:detail' my_listing.id %}">View</a></td>
	<td></td>
	<td><a class="btn" href="">Edit</a></td>
	<td><a class="btn" href="">Delete</a></td>
</tr>
{% endfor %}

This gives a list of all items, once users are setup this list can be filtered by user item.


Next: Django Edit Items
Previous: Django Dynamic Content