Opened 13 years ago

Closed 13 years ago

#17031 closed New feature (wontfix)

Enable ModelForm to display as read-only

Reported by: ferdonline@… Owned by: nobody
Component: Forms Version: 1.3
Severity: Normal Keywords: read-only ModelForm
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

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!

Change History (1)

comment:1 by Alex Gaynor, 13 years ago

Resolution: wontfix
Status: newclosed

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.

Note: See TracTickets for help on using tickets.
Back to Top