How to get value of mutiplecheckboxes in django.
the below code showing the groups at frontend
{% for group in groups %}
<tr><td>{{group.name}}</td>
<td><input type="checkbox" name="superuser" id="group-{{group.id}}" value="{{group.id}}"></td>
</tr>
{% endfor %}
I want to get the values of all checked boxes at backend when I submit the record.
CodePudding user response:
here is a way that i used and worked, try this may help you :)
in your html file:
{% for group in groups %}
<tr><td>{{group.name}}</td>
<td><input type="checkbox" name="superuser[]" id="group-{{group.id}}" value="{{group.id}}"></td>
</tr>
{% endfor %}
and in your view:
checked_group=request.POST.getlist('superuser[]')
so the checked_group will be a list contains all checked group ids.