Python/django: How To Show Both Main Model And 'foreign-key Model' Together In Html
Good Day SO, I am a beginner in Django and python, just started learning two days ago. Currently, I am trying to do my filtering of data in views.py and creating a context to be sh
Solution 1:
I think that you are on the right track, but should start from the other end because Crisis is on Plan.
In the views pull planlist instead of crisislist, then you can:
<tbody>
{% if planList %}
{% for plan in planList %}
<tr><td>{{ plan.crisisID.crisis_ID }}</td><td><ahref="/report/{{ panel.crisisID.crisis_ID}}">{{ crisis.crisis_name }}</a></td><td>{{ plan.crisisID.crisis_dateTime }}</td><td>{{ plan.plan_ID }}</td><td>{{ plan.planstatus }}</td></tr>
{% endfor %}
{% else %}
<p>No crisis available.</p>
{% endif %}
</tbody>
Oh and you should probably swap the query to something like:
planList = Plan.objects.filter(crisis_ID__crisis_status='Ongoing').order_by('-crisisID__crisis_ID')
Post a Comment for "Python/django: How To Show Both Main Model And 'foreign-key Model' Together In Html"