我的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
如何使用'flat_house.adress'
或任何其他html标记包装<a>
?例如,<a href="{% url 'id' %}"
。现在我只显示<td>
标记中列的数据。
我的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>
答案 0 :(得分:2)
检查一下。 django-datatables-view
你可以使用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)