If we need to add more validation in django admin user add form like making the first name and last name and email compulsory.. Whats the way of achieving this??
You must create your own user form and adding your required fields:
class UserForm(forms.ModelForm):
class Meta:
model = User
def __init__(self, *args, **kwargs):
super(UserForm, self).__init__(*args, **kwargs)
self.fields['email'].required = True
self.fields['first_name'].required = True
self.fields['last_name'].required = True
Then override the form in your ModelAdmin:
class UserAdmin(admin.ModelAdmin):
form = UserForm
And then unregister the normal admin User before registering your own:
admin.site.unregister(User)
admin.site.register(User, UserAdmin)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With