您可以使用模板列。这里有我能想到的最简单的模型。当然,您需要将模板更改为更有用的东西。
countries = [
{'name': 'Australia', 'population': 21, 'tz': 'UTC +10', 'visits': 1},
{'name': 'Germany', 'population': 81, 'tz': 'UTC +1', 'visits': 2},
{'name': 'Mexico', 'population': 107, 'tz': 'UTC -6', 'visits': 0},
]
template = """
<select>
<option{% if record.visits = 0%} selected {% endif %}>0
<option{% if record.visits = 1%} selected {% endif %}>1
<option{% if record.visits = 2%} selected {% endif %}>2
</select>
"""
class CountryTable(tables.Table):
name = tables.Column()
population = tables.Column()
tz = tables.Column(verbose_name='time zone')
visits = tables.TemplateColumn(template)