Opened 12 years ago

Closed 12 years ago

#18567 closed New feature (duplicate)

readonly_fields for ModelForms

Reported by: Lacrymology Owned by: nobody
Component: Forms Version: 1.4
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I think it'd be very useful for ModelForm to support the same behavior as ModelAdmin's readonly_fields.

If not, here's a plausible ReadonlyWidget code.

class ReadOnlyWidget(forms.Widget):

    def __init__(self, original_value, display_value):
        self.original_value = original_value
        self.display_value = display_value
        super(ReadOnlyWidget, self).__init__()

    def _has_changed(self, initial, data):
        return False

    def render(self, name, value, attrs=None):
        if self.display_value is not None:
            return unicode(self.display_value)
        return unicode(self.original_value)

    def value_from_datadict(self, data, files, name):
        return self.original_value

Change History (1)

comment:1 by Aymeric Augustin, 12 years ago

Resolution: duplicate
Status: newclosed

Duplicate of #17031.

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