As others have said, at this point there is no self
. Something like this really works:
class FooForm(forms.ModelForm): foo_field = forms.ModelChoiceField() def __init__(self, *args, **kwargs): super(FooForm, self).__init__(*args, **kwargs) self.fields['foo_field'].initial = self.data
You can also access the widget in __init__
through self.fields['foo_field'].widget
dgel
source share