You need to choose a suitable value for the CheckBoxColumn
. Generally if you're displaying a queryset, you'll use the pk
of each object for the CheckBoxColumn
. In your case this would look like:
class EnrollmentTable(tables.Table):
selection = tables.CheckBoxColumn(accessor='pk')
student = tables.Column()
class = tables.Column()
Then you'll need to render the table within a form, so that the user can submit the form, e.g.:
<form action="/someurl/" method="post">
{% load render_tables from django_tables2 %}
{% render_table table %}
<input type="submit"/>
</form>
Then you'll need a view hooked up to /someurl/
. In your case the view will need to look at the POST
variable selection
:
def someview(request):
if request.method == "POST":
pks = request.POST.getlist("selection")
selected_objects = SomeModel.objects.filter(pk__in=pks)
# do something with selected_objects
else:
# ...
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…