39👍
✅
Just need to switch the init function round so that super is called before adding anymore fields.
class StaffForm(forms.ModelForm):
def __init__(self, user, *args, **kwargs):
super(StaffForm, self).__init__(*args, **kwargs)
if user.pk == 1:
self.fields['profile'] = forms.CharField(max_length=200)
self.fields['profile'].initial = 'whatever you want'
class Meta:
model = Staff
👤John
Source:stackexchange.com