Hej!
I have a model for institutions which includes an attribute for parent institutions related to itself
class Institution(models.Model):
name = models.CharField(
max_length=200,
)
parent_institution = models.ForeignKey(
"self",
on_delete=models.SET_NULL,
blank=True,
null=True,
help_text=_("if applicable"),
)
in my template for a DetailView I want not only the parents shown but the ‘childern’ so all institutions where the institution id of the shown institution equals the parent_institution id of one or multiple institutions in my data base.
I tried
{% if institution.id == institution.all.parent_institution.id %}
{{institution.name}}
{% endif %}
which doesn’t show me anything.
or
{% if institution.all.id == institution.parent_institution.id %}
{{institution.name}}
{% endif %}
which gives me the name of the ‘current’ institution, not its childre.
same as:
´´´
{% for child in institutions.all %}
{% if child.id == institution.parent_institution.id %}
{{institution.name}}
{% endif %}
{% endfor %}
´´´
Does anyone know how to achieve that? Is that even possible?