I started using Django and moved on to general concepts. Great architecture! Well, the docs are great, but for an absolute beginner, this is a bit like unix docs, where they make the most sense when you already know what you are doing. I searched and canβt find it specifically, that is, how do you customize the object_list template so that you can click on an entry on the rendering screen and get the object_ detail?
Works. The reason I ask is to check if I am taking a reasonable route, or is there some better, simpler Djangoish way?
I have a model that has unicode so that I can identify my records in the database in a human readable form. I want to click the link on the page generated by object_list to go to the page object_detail. I understand that a good way to do this is to create a system in which the part URL looks like http://www.example.com/xxx/5/ , which would call the page detail for row 5 in the database. So, I just came up with the following, and my question is: Am I on the right track?
I created a template page for a list view containing the following:
<ul> {% for aninpatient in object_list %} <li><a href='/inpatient-detail/{{ aninpatient.id }}/'>{{ aninpatient }}</a></li> {% endfor %} </ul>
Here object_list appears from the general view of list_detail.object_list. The for loop processes a list of object_list objects. In each row, I create an anchor in html that references the desired href, "/ inpatient-detail / nn /", where nn is the id field of each row in the database table. The displayed link is a unicode string, which is therefore a clickable link. I created templates and it works fine.
So, am I going in the right direction? It looks like it will be easy to expand to be able to add and edit links in the template.
Is there a general view that the model uses to create the detail page? I used the ModelForm helper from django.forms to create a form object that is great for creating an input form (with automatic validation! Wow, which was cool!), So is there something similar for creating a detail view page?
Steve