I have a form in Django that looks like this
class FooForm(forms.ModelForm):
foo_field = forms.ModelChoiceField(widget=FooWidget(def_arg=self.data))
Where I call self.data, Python throws the exception name 'self' is not defined. How can I access self there?
As others have answered, there is no
selfto refer to at that point. Something like this does work though:You can also access the widget in
__init__throughself.fields['foo_field'].widget