In django 1.9, in the available Field.disabled attribute: https://docs.djangoproject.com/en/1.9/ref/forms/fields/#disabled
A disabled boolean argument, when set to True, disables the form field using the disabled HTML attribute so that it is not editable by users. Even if the user discards the value of the fields sent to the server, it will be ignored in favor of the value from the original form data.
otherwise
use widget attribute 'readonly'
class PatientForm(forms.ModelForm): def __init__(self, *args, **kwargs): super(PatientForm, self).__init__(*args, **kwargs) self.fields['field'].widget.attrs['readonly'] = True class Meta: model = Patient
mtt2p
source share