小编Kru*_*ake的帖子

单元格颜色 Django-Tables2

问题:我在哪里编辑我的 django 代码以根据业务逻辑更改单个单元格的背景颜色?

在我的 views.py 中,我有捕获列“pts”最大值的逻辑:

def show_teams(request):
reg = Teamoffense.objects.filter(~Q(rk='RK'))
pts = Teamoffense.objects.filter(~Q(pts='PTS')).values('pts')
seq = [item['pts'] for item in pts]
maxseq = max(seq)

table = SimpleTable(reg)
table_to_report = RequestConfig(request).configure(table)
if table_to_report:
    return create_report_http_response(table_to_report, request)
return render(request, 'index.html', {
    'table': table,
    'reg': reg,
    'maxseq': maxseq,
})
Run Code Online (Sandbox Code Playgroud)

如何在该列中呈现最大值为 bgcolor = 'green' 的任何单元格?我目前有一个简单的表格,显示如下:

class SimpleTable(TableReport):

class Meta:
    model = Teamoffense
    exclude = ("column1","column2")
    exclude_from_report = ("column1","column2")
    attrs = {'class': 'paleblue'}
Run Code Online (Sandbox Code Playgroud)

django django-templates django-views django-tables2

2
推荐指数
1
解决办法
1803
查看次数