I have a custom user model extending AbstractUser. I have added two custom fields. But i want the default email field to be uniqe and required . I have searched a lot on the net, but could not find a good advice.
Is it the right way to do that in extended usercreationform with overridden 'clean_email' method?
Thanx
Im facing the same problem, I'm extending the AbstractUser as I only need to add info. This was the only thing that worked for me:
AbstractUser._meta.get_field('email')._unique = True
That solves the unique problem, but still I can't make it required, when you extend AbstractUser it email field IS NOT, it can be noticed if you add a extended user from the admin and also because the forms dont take it that way.
I've tried
AbstractUser._meta.get_field('email')._blank = False
AbstractUser._meta.get_field('email')._null = False
But it doesn't seem to work.
EDIT: For some reason unique works with '_', but blank and null don't, I just tried this
AbstractUser._meta.get_field('email').blank = False
AbstractUser._meta.get_field('email').null = False
And it worked!
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