<分区>
我有一个名为 TestResults 的 Django 模型
模型.py
Class TestResults(models)
chemical_name charfield
value floatfield
unit charfield
method charfield
normal_limit charfield
caution_limit charfield
color charfield
现在,
下面的代码将生成 oils 表,其中包含以下字段。
View .py
fields = ('Test Name', 'Value', 'Unit', 'Method',
'Normal Limit', 'Caution Limit')
all_oils = [(test.chemical_name, test.value, test.unit, test.method,
test.normal_limit, test.caution_limit)
for test in TestResult.objects.all())]
oil_table = Table([fields] + all_oils
oil_table.setStyle(TableStyle([('BACKGROUND', (0, 0), (-1, 0), '#a7a5a5'),
('FONTSIZE', (0, 0), (-1, 0), 6),
('GRID', (0, 0), (-1, -1), 2, '#a7a5a5'),
('FONTSIZE', (0, 0), (-1, -1), 8),
('FONTNAME',(1,1),(1,-1),'Times-Bold')]))
现在如何为每一列提供动态颜色。假设我的 TestResult 模型有颜色字段 (I,e color=red)
在报告中我想要来自模型对象的第二列的动态颜色
我怎样才能做到这一点?