Prevent deletion of some rows in a formset
|Reported by:||shadfc||Owned by:||nobody|
|Has patch:||no||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
Original post to dev mailing list: http://groups.google.com/group/django-developers/browse_frm/thread/5008b34e29c80417
I need to prevent deletion of some of the rows on an inline modelformset.
At first I thought I could just do some validation in clean() and
attach errors to the "DELETE" (really the field mapped to
on the formset ignores errors on forms when can_delete is True.
A few possible solutions:
- Modify formset validation to ignore errors on the forms EXCEPT on the field referenced by forms.formsets.DELETION_FIELD_NAME ("DELETE" normally).
- Make the behavior of ignoring validation errors when can_delete is True explicit. Add a parameter such as "ignore_validation_on_delete" which defaults to True for backward compatibility. When False, formset validation fails on any errors.
- Allow can_delete to be specified per form in a formset, perhaps in a way similar to initial -- an iterable of boolean values.
- Add a pre-delete hook on model forms which can be used to circumvent deletion.
Change History (5)
comment:1 Changed 7 years ago by
|Patch needs improvement:||unset|
|Triage Stage:||Unreviewed → Accepted|