Question

I render a table with django-tables2.This is it:

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'}

I have a template column(id) that each cell of it has a button that each one renders a template. In the view that handles this template I want to pass the value of the cell next to the button cell (same row->plate). This value will be used to query the object that I want to render in a form on the new template with the button click. How can i fetch the value of the next django table cell(plate) when the user "hits" the button?

Was it helpful?

Solution

TemplateColumn renders the template using a context containing a record variable (as described in the documentation).

In your case, this means in editButton.html you can access the plate value via {{ record.plate }}.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top