问题
I'm working on a project using PythoN(3.7) & Django(2.2) in which I have to create 4 different types of users with different fields but they will share some common fields like title & name etc. But I also need to use email
as the username and need to provide different signup form but one login form.
I'm currently using django-allauth
to implement my user management and setup the email
as the username.
Here's what I did:
From models.py
:
class CustomUser(AbstractUser):
# add common fields in here
def __str__(self):
return self.email
From forms.py
:
class CustomUserCreationForm(UserCreationForm):
class Meta:
model = CustomUser
fields = '__all__'
class CustomUserChangeForm(UserChangeForm):
class Meta:
model = CustomUser
fields = ('username', 'email', 'address')
But i'm really confused how can I setupt he multiple type users as I need the following types of users:
- Personal Account - below 18
- Personal Account - above 18
- Parent Account
- Coach Account
- Admin
'Someone suggest that I should create separate apps for all type of users like
personal
,parent
&coach
and then adddjango-allauth
within these apps and I will share the same login page in the parent app. But I don't know how it can be implement?
How can I achieve this behaviour?
回答1:
Create a user Database, in there create 4 user tables for each type of user. Create a function that checks what type of user is being registered based on the data provided.
来源:https://stackoverflow.com/questions/59152070/python-multiple-type-users-with-custom-user-model-in-django-allauth