class CourtColumn(tables.Column):
def render(self, value):
if value == 'Hard':
self.attrs ={"td": {"bgcolor": "DeepSkyBlue"}}
elif value == 'Clay':
self.attrs ={"td": {"bgcolor": "SandyBrown"}}
class TodayTable(tables.Table):
Rank = tables.Column(accessor='tour.rank_t',orderable=True)
Tour = tables.Column(accessor='tour.name_t')
Court = CourtColumn(accessor='tour.id_c_t.name_c',verbose_name= 'Court')
...
def render_Tour(self, record):
if record.tour.rank_t == 0:
self.attrs ={"td": {"bgcolor": "Violet"}}
return u"%s" % (record.tour.name_t)
我到法院...... td bgcolor =“SandyBrown” class =“Court”> Clay< ... - ОК。如何进入同一巡回赛,但使用另一列的值? def render_Tour无法按要求工作
答案 0 :(得分:0)
子类tables.Column并利用记录参数:
class TourColumn(tables.Column):
def render(self, value, record):
if record.tour.rank_t == 0:
self.attrs ={"td": {"bgcolor": "Violet"}}
return u"%s" % (record.tour.name_t)
然后在表中使用该类:
Tour = TourColumn(accessor='tour.name_t')