Adding Checkbox to django-tables2 - Key Error

800 views
Skip to first unread message

Thorsten Grahl

unread,
Nov 8, 2016, 7:03:36 AM11/8/16
to Django users
Hi,

Django noob here, am stuck and can not find an example to help me past my error.

Using the tutorial (https://django-tables2.readthedocs.io/en/latest/pages/tutorial.html) have managed to display the table.
Could now like to add a checkbox to each row, so the user can select multiple rows and then select a button at the bottom of the table for further processing of those rows.
But am getting following error  Exception Type: Key Error Exception Value: 'selection'

tables.py
import django_tables2 as tables
from .models import Person

class PersonTable(tables.Table):
    class Meta:
        model = Person
        #selection = tables.CheckBoxColumn(accessor="pk", attrs = { "th__input": {"onclick": "toggle(this)"}}, orderable=False)
        selection = tables.CheckBoxColumn(accessor='pk', orderable=False)
        attrs = {'class': 'paleblue'}
        sequence = ('...', 'selection')

views.py
def people(request):
#return render(request, 'application/people.html', {'people': Person.objects.all()})
table = PersonTable(Person.objects.all())
RequestConfig(request).configure(table)
return render(request, 'application/people.html', {'table': table})


Regards,
Thorsten
Reply all
Reply to author
Forward
0 new messages