Advertisement
horozov86

MIXINS IN DJANGO

Aug 28th, 2024
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.54 KB | None | 0 0
  1. class ReadonlyFieldsMixin:
  2.     readonly_fields = ()
  3.  
  4.     def _mark_readonly_fields(self):
  5.         for field_name in self.readonly_fields:
  6.             self.fields[field_name].widget.attrs["readonly"] = "readonly"
  7.         # for _, field in self.fields.items():
  8.         #     field.widget.attrs["readonly"] = "readonly"
  9.  
  10.  
  11. class UpdatePersonForm(ReadonlyFieldsMixin, PersonForm):
  12.     readonly_fields = ("age", "last_name")
  13.  
  14.     def __init__(self, *args, **kwargs):
  15.         super().__init__(*args, **kwargs)
  16.  
  17.         self._mark_readonly_fields()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement