【发布时间】:2019-07-14 16:01:36
【问题描述】:
我正在构建一个仪表板,您可以在其中交叉销售数据库中的数据。
例如,卖家的销售额,客户的产品等。我让用户选择选项1和选项2。
我将表单返回到视图并使用这些选项对模型进行注释:
if filter_opts.is_valid():
option_1 = filter_opts.cleaned_data["option_1"]
option_2 = filter_opts.cleaned_data["option_2"]
results = ventas.values(option_2).annotate(Count(option_1, distinct=True))
注释工作正常,如果我只是在模板中打印查询集
{% for case in results %}
{{ case }}
{% endfor %}
我可以这样看:
{'cliente': '502 EMSUR', 'prod_nombre__count': 9}
然后在模板中我只想显示值。但是我不能正手告诉哪个值名称来做这样的事情:
{% for case in results %}
{{ case.option_1 }}
{{ case.option_2 }}
{% endfor %}
如果我遍历结果,我可以看到字段名称:
{% for case in results %}
{% for item in case %}
{{ item }}
{% endfor %}
{% endfor %}
如何显示这些字段的值?
谢谢!
【问题讨论】:
标签: django django-templates django-queryset