【问题标题】:add link or any html tag to column in django-datatables-view将链接或任何 html 标记添加到 django-datatables-view 中的列
【发布时间】:2016-08-21 22:49:49
【问题描述】:

我的 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

如何用<a> 或任何其他html-tag 包装'flat_house.adress'?例如,<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>

【问题讨论】:

    标签: python django datatable datatables django-datatable


    【解决方案1】:

    检查一下。 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)
    

    【讨论】:

      猜你喜欢
      • 2020-07-15
      • 2013-05-26
      • 2019-10-04
      • 1970-01-01
      • 2011-03-03
      • 2011-10-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-18
      相关资源
      最近更新 更多