Я довольно новый в Django ... Мой вопрос: как я могу получить имя «self foreign key» в шаблоне через listView? Благодаря ...Показать ссылки в шаблоне
models.py
class Organization(Model.models):
name = models.CharField(max_length=100)
mother_organization = models.ForeignKey('self',
null=True,
blank=True,
related_name='mother'
)
views.py
class List(ListView):
model = Organization
context_object_name = "organizations"
template_name = "organizations.html"
organizations.html
{% for organization in organizations %}
<p>
{{ organization.reference }}
{{ organization.name }}
test 0 : OK !!
{{ organization.mother_organization.name|default:"-" }}
test 1 : FAIL
{{ organization.mother.name|default:"-" }}
test 2 : FAIL
{% for mother in organization.mother.all %}
{{ mother.name }}
{% empty %}
test 3 : FAIL
{% for mother in organization.mother_organization.all %}
{{ mother.name }}
{% empty %}
#
{% endfor %}
</p>
{% endfor %}
Что не работает? – Sayse