gpt4 book ai didi

python - Reportlab:reportlab中表列的动态颜色(存储在django模型中的颜色)

转载 作者:太空宇宙 更新时间:2023-11-03 11:09:43 25 4
gpt4 key购买 nike

<分区>

我有一个名为 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)

在报告中我想要来自模型对象的第二列的动态颜色

我怎样才能做到这一点?

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com