Django inline formset for each object delete

风格不统一 提交于 2020-01-07 11:02:14

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!