ConoscereLinux / asso-django

An open source Django Framework to manage Events, Member and basic Accounting for an Italian Association
GNU General Public License v3.0
0 stars 3 forks source link

Proposal for User/Member structure #31

Closed giobber closed 1 year ago

giobber commented 1 year ago

Objective

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)
    ...

Reference

What to do to avoid CircularDependencyError error on migrations

link to documentation

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

giobber commented 1 year ago

After a more careful analysis (with collaboration of @ZompaSenior) we decide to not support multiple mail access