I have a page that lets the viewer edit objects. The page displays a formset with one form for each object, plus one empty form should they wish to create an object, and I would like there to be a checkbox marked “Delete” under each pre-existing object (which is to say, NOT the last one because it’s the extra empty form).
I added the following code to my template:
{% for form in formset %}
{{ form.as_p }}
{% if forloop.last %}
{% else %}
Delete?<input type="checkbox" name="delete" value="delete"><br>
{% endif %}
{% endfor %}
This displays the checkbox, but I don’t know how to get the data about whether or not that box was checked when I am processing the form.
For background, I’m creating the formset with modelformset_factory(MyClass, extra=1) and I’m not just using can_delete because I don’t want a delete checkbox to appear under my last and empty form, so I’d prefer to simply add an extra input directly in the template, if that’s possible.
How would I get the data about whether or not that box has been checked?
As it is form, so you have got method that process it? So you can just get flag value of it with request.POST.getlist(‘delete’)