[Answer]-Accordion Table Django Template

1👍

For a jQuery Accordion, see here: http://jqueryui.com/accordion/

That can get you started on the right track. From there, you just need to output the data using Django’s template system beforehand.

Note that you can access the child objects from a parent by calling .childmodelname_set, which is the lowercase name of the child model and _set. You can loop through this set to output the child objects within the template:

{% for object in objects %}
    {{ object.object_id }}
    {{ object.name }}
    {{ object.object_type }}
    ...
    {% for child in object.child_set.all %}
        {{ child.child_id }}
        {{ child.name }}
        {{ child.description }}
        ...
    {% empty %}
        No children!
    {% endfor %}
{% empty %}
    No objects!
{% endfor %}

In this case, you would build your template with an accordion such that all child data in the inner for loop is generated for that accordion tab’s contents.

Using the above-linked Accordion from jQueryui, you’d have to rebuild the data output using <div> and <h3> tags: you can build individual tables within them, but it won’t be perfect.

Alternatively, since it looks like you’re using Bootstrap, you can write divs in the grid system, instead.

👤G Rice

Leave a comment