Opened 13 years ago
Closed 13 years ago
#18567 closed New feature (duplicate)
readonly_fields for ModelForms
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
Note:
See TracTickets
for help on using tickets.
Duplicate of #17031.