1👍
✅
The html template has to know the pk of the object to get the list of the objects.
class XMLFORMTable(tables.Table):
eliminar = tables.CheckBoxColumn(accessor='pk')
class Meta:
model = XML_FORM
exclude = ['id_form','obs']
If you give the pk to the value of the checkbox, you retrieve the value list of checked elements.
import render
def XMLFieldsView(request):
if request.method == 'POST':
lista = request.POST.getlist('eliminar')
""" Here I am lost """
for pk in lista:
get_object_or_404(ElObjeto, pk=pk).delete()
else:
....
return render(request, listacampos.html,{'table':tabla,'form':form,'lista':lista})
Also render, is a shortcut for render_to_response in that will automatically use RequestContext
Source:stackexchange.com