Add a hook for specifying whether a form in a formset should be deleted
|Reported by:||Brett Hoerner||Owned by:||jkocherhans|
|Severity:||Normal||Keywords:||admin forms formset deletion|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
save_existing_objects currently uses form._raw_value to check the DELETION_FIELD_NAME,
if self.can_delete: raw_delete_value = form._raw_value(DELETION_FIELD_NAME) should_delete = form.fields[DELETION_FIELD_NAME].clean(raw_delete_value) if should_delete: self.deleted_objects.append(obj) obj.delete() continue
Is there any reason it can't use form.cleaned_data.get(DELETION_FIELD_NAME, False) instead? By using _raw_value we prevent users from deciding to flag an inline for deletion during form validation.
if self.can_delete: should_delete = form.cleaned_data.get(DELETION_FIELD_NAME, False) if should_delete: self.deleted_objects.append(obj) obj.delete() continue
Use case: Inline FormSet in the admin that detects certain inlines _should_ be deleted based on other information, and there is no need to bug to admin user for confirmation.
Definitely exists in 1.0.x and trunk.
Change History (14)
comment:1 Changed 8 years ago by
|Patch needs improvement:||unset|
comment:4 follow-up: 5 Changed 8 years ago by
|Patch needs improvement:||set|
|Summary:||save_existing_objects in forms.models should use cleaned_data and not _raw_value → Add a hook for specifying whether a form in a formset should be deleted|
|Triage Stage:||Unreviewed → Accepted|