[英]add link or any html tag to column in django-datatables-view
I've got django-datatables-view looking like this: 我有django-datatables-view看起来像这样:
class OrderListJson(BaseDatatableView):
model = Flat
columns = ['id', 'flat_price', 'flat_house.house_block.block_name']
order_columns = ['flat_price', 'flat_house.house_block.block_name']
max_display_length = 100
def filter_queryset(self, qs):
search = self.request.GET.get(u'search[value]', None)
if search:
qs = qs.filter(flat_price__lte=search)
return qs
How to wrap 'flat_house.adress'
with <a>
or any other html-tag? 如何用
<a>
或任何其他html标签包装'flat_house.adress'
? For example, <a href="{% url 'id' %}"
. 例如,
<a href="{% url 'id' %}"
。 Right now I only show the data from the column in a <td>
tag. 现在,我仅在
<td>
标记中显示列中的数据。
My html-template looks like this: 我的html模板看起来像这样:
<table id="datatabletest" class="table table-striped table-bordered" cellspacing="0">
<thead>
<tr>
<th>id</th>
<th>price</th>
<th>adress</th>
</tr>
</thead>
<tfoot>
<tr>
<th>id</th>
<th>price</th>
<th>adress</th>
</tr>
</tfoot>
</table>
check this. 检查一下。 django-datatables-view
django-datatables-view
you can use render_column method for this. 您可以为此使用render_column方法。
def render_column(self, row, column):
# i recommend change 'flat_house.house_block.block_name' to 'address'
if column == 'address':
return '<a href="%s">link</a>' % row.flat_house.house_block.block_name
else:
return super(OrderListJson, self).render_column(row, column)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.