views:

99

answers:

1

I'm not sure if I just can't concentrate or what, but I feel like this should be easy to do. I have 2 models, one that references the other as a simple foreign key relation (one-to-many) now in the template I want to display this relation as a nested unordered lists.

+3  A: 

Not quite sure what you mean, but perhaps:

<ul>
    {% for foo in foo_list %}
    <li>
        {{ foo }}
        <ul>
            {% for bar in foo.bar_set.all %}
            <li>{{ bar }}</li>
            {% endfor %}
        </ul>
    </li>
    {% endfor %}
<ul>

Obviously, foo_list must be in the context, and bar has a foreign key relation to foo with no related_name.

ozan
AH! Exactly what I was looking for! - sorry for not providing code excerpts. Thank you.
KeyboardInterrupt