Mixing read-only with ability to add new instances using a FormSet
|Reported by:||coleifer||Owned by:||nobody|
|Cc:||apollo13, jdunck@…, wiml@…||Triage Stage:||Accepted|
|Has patch:||no||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
A little background, I've been attempting to add permission-awareness to admin inlines using a technique like the one mentioned here:
The problem occurs when I want to allow a user to be able to add new inline instances, but display the pre-existing ones as read-only. By overriding the get_readonly_fields() method in the event the user doesn't have change permissions, I'm able to make everything read-only...but this includes the formset's "extra_forms", or when the user clicks to add a new row.
Since read-only is an admin thing and is implemented in the formset-level as "exclude", it's going to be kind of tricky to tell, using just the FormSet API, which fields are actually excluded and which are just read-only. I would propose making readonly_fields an attribute of the form, just like exclude. Additionally, it makes sense to me for any 'extra_forms' on the FormSet to display all non-excluded fields as editable. Having a read-only field on a form that does not contain any data is odd.
Change History (10)
comment:1 follow-up: ↓ 2 Changed 6 years ago by russellm
- Needs documentation unset
- Needs tests unset
- Patch needs improvement unset
- Triage Stage changed from Unreviewed to Design decision needed