django-tables2:获取单元格值

时间:2012-09-05 17:40:15

标签: django-tables2

我用django-tables2渲染一个表。就是这样:

class VehiclesTable(tables.Table):
    id = tables.TemplateColumn(verbose_name=' ',template_name='editButton.html')
    plate = tables.Column(verbose_name='plate')
    vht_id = tables.Column(verbose_name='vht_i')
    vlength = tables.Column(verbose_name='vlength')
    vwidth = tables.Column(verbose_name='vwidth')

    class Meta:
       attrs = {'class': 'custom'}

我有一个模板列(id),它的每个单元格都有一个按钮,每个按钮都会呈现一个模板。在处理此模板的视图中,我想传递按钮单元格旁边的单元格的值(相同的行 - >板)。此值将用于通过单击按钮查询要在新模板上的表单中呈现的对象。当用户“点击”按钮时,如何获取下一个django表格单元格(板)的值?

1 个答案:

答案 0 :(得分:4)

TemplateColumn使用包含record变量的上下文呈现模板(如documentation中所述)。

在您的情况下,这意味着在editButton.html您可以通过plate访问{{ record.plate }}值。

相关问题