Search code examples
djangodjango-tables2

Using "record" in attributes Django Tables 2


I'm moving my tables to django-tables2. By now is almost everything working ok, but now I have a problem.

In my current version i use checkboxes to select items

<td><input type="checkbox" class="checkbox_delete" name="event" id="event.id"
                                               value="{{ event.id }}" />

this way in the view i can recover the event.id using request.POST.getlist('event')

Now I'm trying to add the "value" attribute to a CheckBoxColumn

select = tables.CheckBoxColumn(attrs={'td__input': {'class': 'checkbox_delete', 'name': 'event', **'value': [A('id')]**}, 'th__input': {'id': 'selectAll'}},
                                   empty_values=())

I've been playing with the Accesor and the record.id which I use in a templateColumn.

How can I pass the id to the value attribute??


Solution

  • I found another solution here How to get information from Django_tables2 row?

    Just need to define select = tables.CheckBoxColumn(accessor='pk') and it add the value as the record.id