mydata.append({
'bool_access': True,
'path': path
})
table = mytable(data=mydata)
----> render table
class mytable(tables.Table):
path = tables.Column(verbose_name='My path')
# path = tables.LinkColumn('page_web', args=[A('path')],verbose_name='My path')
bool_access = ""
class Meta:
attrs = {'class': 'table table-bordered table-striped table-condensed'}
sequence = ('path')
Я хочу, чтобы если добавить строку в мои данные с bool_access
в «Истина», тип столбца для path
будет tables.LinkColumn
, а если bool_access
в «Ложь», тип столбца будет tables.Column
.
Заранее благодарю за любую помощь.
Есть несколько способов подойти к этому, но я думаю, что самый простой - использовать TemplateColumn
:
class MyTable(tables.Table):
path = tables.TemplateColumn(
verbose_name='My path',
template_code = """{% if record.bool_access %}<a href = "{% url "page_web" record.path %}">{{ record.path }}</a>{% else %}{{ record.path }}{% endif %}""")
class Meta:
attrs = {'class': 'table table-bordered table-striped table-condensed'}
sequence = ('path')