You need to select the appropriate value for CheckBoxColumn
. Typically, if you show a set of queries, you will use pk
for each object for CheckBoxColumn
. In your case, it will look like this:
class EnrollmentTable(tables.Table): selection = tables.CheckBoxColumn(accessor='pk') student = tables.Column() class = tables.Column()
Then you will need to display the table in the form so that the user can submit the form, for example:
<form action="/someurl/" method="post"> {% load render_tables from django_tables2 %} {% render_table table %} <input type="submit"/> </form>
Then you need a view connected to /someurl/
. In your case, the view should look at the POST
selection
variable:
def someview(request): if request.method == "POST": pks = request.POST.getlist("selection") selected_objects = SomeModel.objects.filter(pk__in=pks)
source share