1👍
You shouldn’t set self.exclude
in the get_form
method, it’s not thread safe. Instead, you can define two different form classes, and return the correct one depending on user.is_superuser
.
class EmployerForm(forms.ModelForm):
class Meta:
model = Employer
fields = ['employer_verified',]
class EmployerSuperUserForm(forms.ModelForm):
class Meta:
model = Employer
def get_form(self, request, obj=None, **kwargs):
if request.user.is_superuser:
return EmployerSuperUserForm
else:
return EmployerForm
self.fields=['employer_verified']
Source:stackexchange.com