1👍
✅
You’re giving multiple elements the same id which is never a good idea, you can append the id of the subject to the target/id of the elements to give them unique id’s
{% for subject in subjects %}
<span data-subject="{{subject.id}}"
data-toggle="collapse"
data-target="#books_list{{ subject.id }}">
{{subject.name}}
</span>
<div id="books_list{{ subject.id }}">
{% for book in subject.books_set.all %}
<span>{{book.name}}</span>
{% endfor %}
</div>
{% endfor %}
Source:stackexchange.com