Sorry, Ken.
Would you just clarify something for me, please?
If I stick with the existing user model which i think is auth_user
and just add this:
from django.contrib.auth.models import AbstractUser, BaseUserManager, PermissionsMixin, Group, Permission
class UserAccount(AbstractUser, PermissionsMixin):
email = models.EmailField(unique=True)
username = models.CharField(max_length=40, unique=True)
first_name = models.CharField(max_length=40)
last_name = models.CharField(max_length=40)
is_staff = models.BooleanField(default=False)
is_active = models.BooleanField(default=True)
date_joined = models.DateTimeField(auto_now_add=True)
objects = UserAccountManager()
groups = models.ManyToManyField(Group, blank=True, related_name='user_accounts')
user_permissions = models.ManyToManyField(
Permission,
blank=True,
related_name='user_accounts'
)
USERNAME_FIELD = 'email'
REQUIRED_FIELDS = ['username', 'first_name', 'last_name']
def get_full_name(self):
return f"{self.first_name} {self.last_name}"
def get_short_name(self):
return self.first_name
def __str__(self):
return self.email
Which allows me to set the email as the login etc. And then within my settings.py
I add:
## AUTHENTICATION SETTINGS ##
AUTH_USER_MODEL = 'backend.UserAccount'
backend being my primary app within my project.
Is this going to be ok? Or whatever I do to make the login email_address
will require me to do some manual data restores etc?
The structure of my project is:
app_backend
-settings.py
backend
-models.py
-views.py
-admin.py
...
So I’m just a bit confused if using
## AUTHENTICATION SETTINGS ##
AUTH_USER_MODEL = 'backend.UserAccount'
is this correct, or i should be using
## AUTHENTICATION SETTINGS ##
AUTH_USER_MODEL = app_backend.UserAccount'
and moving the model into app_backend
and creating a new models.py?
Hope this makes sense.