6👍
✅
You should perform:
self.fields['studentId'].widget.attrs['readonly'] = True
and also make sure not to overwrite the value on postback.
Furthermore, if still having problems with the required field, you can do the following in your modelform:
studentID = forms.CharField(label="A label", help_text="Student ID", required=False)
Source:stackexchange.com