Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class ReadonlyFieldsMixin:
- readonly_fields = ()
- def _mark_readonly_fields(self):
- for field_name in self.readonly_fields:
- self.fields[field_name].widget.attrs["readonly"] = "readonly"
- # for _, field in self.fields.items():
- # field.widget.attrs["readonly"] = "readonly"
- class UpdatePersonForm(ReadonlyFieldsMixin, PersonForm):
- readonly_fields = ("age", "last_name")
- def __init__(self, *args, **kwargs):
- super().__init__(*args, **kwargs)
- self._mark_readonly_fields()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement