[英]django report from model data - print multiple tables
I'm trying to print out a report in table format; 我正在尝试以表格格式打印报告; but need to break the table and start a new one when a specific column changes.
但需要中断表并在特定列更改时开始新的表。
Example Data (in a Model) 示例数据(在模型中)
item1 value group1
item2 value group1
item3 value group2
item4 value group3
output: 输出:
For Group1
- Item1 value
- Item2 value
For Group2
- Item3 value
For Group3
- Item4 value
I get this data from a mysql database... I'm trying output this data in a Template and do all the formatting with template using tags... i tried ifchanged, ifequal (first getting a list of unique groups)... but neither work well (or at all)... 我从mysql数据库中获取此数据...我正在尝试在模板中输出此数据并使用标签对模板进行所有格式化...我尝试了ifchanged,ifequal(首先获取唯一组列表)...但都不行(或根本不行)...
what would be the most efficient way to do this (as there could be several hundred records over numerous/countless groups - so I figured it isn't good to make numerous calls to the database and build an array of Models that contain an array of each group results 这是最有效的方法(因为可能有成百上千的记录分布在众多/不计其数的组中,因此我认为对数据库进行大量调用并构建包含一系列数组的Models并不合适。每组结果
Thoughts? 有什么想法吗?
You can use a loop in a template: 您可以在模板中使用循环:
{% for item in group1 %}
{{ item.value }}
{% endfor %}
{% for item in group2 %}
{{ item.value }}
{% endfor %}
{% for item in group3 %}
{{ item.value }}
{% endfor %}
If you could post the code from your view that would help me answer the question. 如果您可以从自己的角度发布代码,这将有助于我回答问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.