Reputation: 103
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')
I want that if a add a row in my data with bool_access
at "True" that the column type for path
is tables.LinkColumn
and else if bool_access
at "False" the column type is tables.Column
.
Thanks in advance for any help.
Upvotes: 0
Views: 244
Reputation: 4229
There are multiple ways to approach this, but I think the most straightforward one is using a 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')
Upvotes: 1