2016-04-27 10 views
0

をコラムへのリンクまたは任意のHTMLタグを追加し、私はこのように見ているジャンゴ - DataTableのビューを持っている:ジャンゴ - DataTableのビューで

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タグと'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> 

答えて

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)