问题
if formset.is_valid():
values = formset.save(commit=False)
for v in values:
v.correct = True
v.save()
How can I delete objects where delete is checked? Thanks
回答1:
First, in your formset, mark your delete checkboxes with name="form-0-DELETE"
, name="form-1-DELETE"
, etc.
Then in your if form.is_valid and formset.is_valid
iterate over the values marked for delete.
for delete_value in formset.deleted_objects:
delete_value.delete()
Then continue with saving your formset
来源:https://stackoverflow.com/questions/35945065/django-inline-formset-for-each-object-delete