Python - Multiple type users with custom user model in django-allauth

試著忘記壹切 提交于 2019-12-12 06:46:05

问题


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:

  1. Personal Account - below 18
  2. Personal Account - above 18
  3. Parent Account
  4. Coach Account
  5. Admin 'Someone suggest that I should create separate apps for all type of users like personal, parent & coach and then add django-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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!