{% load wnsq_tags %} {% load staticfiles %} {% comment %} generalized snippet to display related (fk) relations in an object's detail view. using templates must provide the object list as related_list and the detail url which leads to the detail view for that particular related object {% endcomment %} {% with rel_count=related_list.count %} {% if rel_count %} {% comment %} since the list isn't empty, we can abuse the first object to lookup the verbose plural name of the related object and use this as a label for the show/hide button and the table header. note that the div id must be reflect the name of the related item, this avoids naming conflicts in detail views with more than one related list. for this purpose we abuse the class name of the model, which can act as a valid html id. {% endcomment %} {% with rel_name_plural=related_list.first.verbose_name_plural class_name=related_list.first|get_class %}
{% for rel_obj in related_list %} {% endfor %}
{% endwith %} {% endif %} {% endwith %}