0π
β
To access the related objects ApprovalProcess
to ApprovalSteps
, you can use _set
(Django Docs).
So in your case in you template approval_item.approval_id_set.all
:
{% for item in approval_item.approval_id_set.all %}
{{ item.doc_id }}
{% endfor %}
in views.py:
approval_item.approval_id_set.all()
Or use ForeignKey.related_name:
approval_id = models.ForeignKey(
ApprovalProcess, on_delete=models.CASCADE, null=True,
related_name="processes"
)
# then you can use
approval_item.processes.all()
Also I recommend you to rename approval_id to approval because:
Behind the scenes, Django appends "_id" to the field name to
create its database column name, see Django ForeignKey
π€NKSM
1π
You can change your approval_details
view function to
def approval_details(request, pk):
approval_items_list = get_list_or_404(ApprovalSteps, approval_id=pk)
return render(request, 'approval_details.html', {'approval_items_list': approval_items_list})
Refer here
π€Kishore Sampath
- [Answered ]-Why are there one model.py per app instead of just one model.py out through the whole project?
- [Answered ]-Modify form fields in FormWizard (Django 1.4)
- [Answered ]-Is there a drawback to adding multiple indexes to a model in Django?
Source:stackexchange.com