【发布时间】:2017-06-27 06:28:56
【问题描述】:
我有 2 张桌子:
Table1: [A-Foriegn Key, field1]
Table2: [Table1-Foriegn Key, field2]
如果表 2 中存在项目,我想显示一个包含表 1 字段 1 的不同值的列表。在该列表中,我想显示与 Table1 的 field1 对应的 Table2 的所有元素。
我正在尝试:
{% for t1 in Table1 %}
Display field1 of t1
{% for t2 in Table2 %}
Display field2 of t2.
{% endfor %}
{% endfor %}
表 1:
╔════╦══════════════╦══════╗
║ Id ║ EventName ║ FK ║
╠════╬══════════════╬══════╣
║ 1 ║ Christmas ║ 56 ║
║ 2 ║ Black Friday ║ 18 ║
╚════╩══════════════╩══════╝
表 2:
╔════╦══════════════╦══════╗
║ ID ║ Image ║ FK ║
╠════╬══════════════╬══════╣
║ 1 ║ image1_url ║ 1 ║
║ 2 ║ image2_url ║ 1 ║
║ 3 ║ image3_url ║ 2 ║
║ 4 ║ image4_url ║ 2 ║
╚════╩══════════════╩══════╝
我想在列表中显示:圣诞节和黑色星期五。
在单击列表中的元素时,我想显示该特定事件的所有 url。 就像点击圣诞节一样:应该显示 image1_url 和 image2_url。
我不想发出 AJAX 请求。
【问题讨论】:
-
能否给出表格中的示例数据和示例输出?
-
我已经添加了示例数据。