Make login available with multiple user emails and username
Structure
class User(AbstractBaseUser):
username = models.CharField(max_length=40, unique=True)
is_active = models.BooleanField(default=True)
is_admin = models.BooleanField(default=False)
password = ...
USERNAME_FIELD = "username"
objects = UserManager()
@property
def email(self):
return self.emails.filter(primary=True).first()
class UserEmail(Model):
email = EmailField(unique=True)
user = ForeignKey(User)
primary = BoolUniqueForUser() # Mail used for communications
# Inside membership module
from django.conf import settings
from django.contrib.auth import get_user_model
class Member:
...
user = OneToOneField(settings.AUTH_USER_MODEL)
...
Create new auth app inside admin (require models.py, admin.py, 'migrationsandapps.py`
Create custom user, without any difference with default user
link that user to auth_user table
Connect new app in settings by:
adding App class in apps.py with name admin.auth
adding admin.auth.apps.AuthApp to settings.INSTALLED_APPS
migrate
make required changes to User class and migrate it
If this not work (and probably will) take a breath, remove all migrations for user and memberships and start anew (fortunately we are still in alpha), the other models migrations will live fine
Objective
Make login available with multiple user emails and username
Structure
Reference
What to do to avoid CircularDependencyError error on migrations
link to documentation
models.py
,admin.py
, 'migrationsand
apps.py`auth_user
tableapps.py
with nameadmin.auth
admin.auth.apps.AuthApp
to settings.INSTALLED_APPSIf this not work (and probably will) take a breath, remove all migrations for user and memberships and start anew (fortunately we are still in alpha), the other models migrations will live fine