我有一个表,用于比较所选数据的两个版本。 该数据实际上存储了多个版本,因此在我的表中我有一列:
class ver_compare(tables.Table):
new_db = tables.CheckBoxColumn()
data = tables.Column()
current_rev = tables.Column()
next_rev = tables.Column()*
现在我希望每个单元格都有一个可供选择的版本下拉列表,类似于 choicefield 的最后一个字段。 有什么方法可以继续吗?
提前致谢!!
最佳答案
您可以使用TemplateColumn。这是我能想到的最简单的模型。当然,您需要将模板更改为更有用的东西。
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)
关于python - 将 django-tables 的列自定义为下拉列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11326234/