I have a python list
readonly = ['name', 'description']
that I wish to use in a few methods. However I get a global variable not defined error
class EditForm(ModelForm):
# When editing form we want to disable multiple fields
# Admin users can edit existing items via admin interface
readonly = ['name', 'description']
def __init__(self, *args, **kwargs):
super(EditForm, self).__init__(*args, **kwargs)
instance = getattr(self, 'instance', None)
for ro_field in readonly:
if instance and instance.pk:
self.fields[ro_field].widget.attrs['readonly'] = True
How do I keep the list local and be able to use it in the __init__
function and subsequent methods without repeating setting the list in each function