from django import forms class ReadOnlyForm(forms.ModelForm): """Base class for making a form readonly.""" def __init__(self, *args, **kwargs): from django.utils.translation import ugettext as _ from django.forms.widgets import Select super(ReadOnlyForm, self).__init__(*args, **kwargs) for f in self.fields: self.fields[f].label = _(self.fields[f].label) if isinstance(self.fields[f].widget, Select): self.fields[f].widget.attrs['disabled'] = 'disabled' else: self.fields[f].widget.attrs['readonly'] = 'readonly'