开发者

Django Nested Relations

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 re开发者_开发技巧lation as a nested unordered lists.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜