Opened 14 years ago
Closed 14 years ago
#17031 closed New feature (wontfix)
Enable ModelForm to display as read-only
Description ¶
It seems there is not an easy way to define a ModelForm as having all its fields "read-only", so that the form can be used for only-displaying info, for instance to a non-authenticated user.
I've seen several people looking for this feature with some nasty workarounds.
A +/- clean hack is to define a function in the child class that goes iterates over the fields and defines the disabled attribute to the corresponding widget, like:
def set_readonly( self ): for field in self.fields: self.fields[field].required = False self.fields[field].widget.attrs['disabled'] = 'disabled'
is there a better way of doing this? If not, can you consider applying this solution to the main class (ModelForm)?
Cheers!
Marking as wontfix (I actually think it's a dupe as well). Froms are for processing data, not rendering it. #342 features further discussion on this issue.