Hello dear Django community,
I am new to this wonderful framework and currently within the learning curve of how to handle custom user models.
I have the following model in my accounts app:
class BlogUser(AbstractBaseUser, PermissionsMixin):
username_validator = UnicodeUsernameValidator()
username = models.CharField(
_("username"),
max_length=150,
unique=True,
help_text=_(
"Required. 150 characters or fewer. Letters, digits and @/./+/-/_ only."
),
validators=[username_validator],
error_messages={
"unique": _("A user with that username already exists."),
},
)
is_active = models.BooleanField(default=True)
is_admin = models.BooleanField(default=False)
objects = BlogUserManager()
EMAIL_FIELD =
USERNAME_FIELD = 'username'
REQUIRED_FIELDS = ['password', ]
And here is a snippet from another app with a profile model extension to the user model:
from django.contrib.auth import get_user_model
class Author(models.Model):
user_id = models.OneToOneField(get_user_model(), on_delete=models.PROTECT)
name = models.CharField(max_length=512)
email = models.CharField(max_length=512, unique=True)
author_page_text = models.TextField(default='', blank=True)
author_page_text_html = models.TextField(default='', blank=True)
author_picture_url = models.CharField(max_length=512, blank=True)
It plays nice with the admin app so far, but it does not play well with the django auth app, which wants to read the email from the EMAIL_FIELD in the user model when submitting a reset password form for example.
I would like to give it the email from the one to one profile model.
Would there be a way to make this happen?
Thank you for your time and knowledge!
Fred