Multi type Member/user creation in Django?

I need to create a paid memebership website with django.There are three types of members to be registered. these registration form/model will have different fields appart from common authentication fields. In the admin panel these member/users should be listed separately from the super user/ admin/staff users. this is the way I understood. Im confused, plese help me to achive this.

class CustomUser(AbstractBaseUser):
first_name = models.CharField(max_length=100)
last_name = models.CharField(max_length=100)
email = models.EmailField(unique=True)
phone = models.CharField(max_length=10)
address= models.TextField()

is_active = models.BooleanField(default=True)
is_staff = models.BooleanField(default=False)

gender_choices = (
    ('M', 'Male'),
    ('F', 'Female'),
    ('O', 'Other'),
gender = models.CharField(max_length=1, choices=gender_choices)

objects = CustomUserManager()


def __str__(self):

class NurseMember(CustomUser):
#common Fileds
nurse_regi_number =
hospital =
#extra nurse specific fields

class StudentMember(CustomUser):
#common Fileds
student_regi_number =
institution =
#extra studentspecific fields

You can use user_types in your CustomUser model file

OWNER = "owner"
CLIENT = "client"
ADMIN = 'admin'
VENDOR = 'vendor'
# EDITOR = 'editor'
MANAGER = 'manager'
EMPLOYEE = 'employee'
DRIVER = 'driver'
GUEST= 'guest'

    (OWNER, "Owner"),
    (MANAGER, "Manager"),
    (ADMIN, "Admin"),
    (EMPLOYEE, "Employee"),
    (VENDOR, "Vendor"),
    (CLIENT, "Client"),
    (REPRESENTATIVE, "Representative"),
    (DRIVER, "Driver"),
    (GUEST, "Guest"),

## Your
class CustomUser(AbstractBaseUser):
    role = models.CharField(
        max_length=25, choices=choices.USER_TYPES, default=choices.CLIENT

you can use it as

if request.user.role == 'client':
      # do what you want with this type of user
elif request.user.role == 'employee':
      # do what you want with this type of user
elif request.user.role == 'guest':
     # do what you want with this type of user

And so on

Hope it helps

1 Like

You can then override the model Manager with one thatadds custom Filter so you can do CustomUser.objects.filter_employees() or .filter_managers().

1 Like

Alternatively to the solutions mentioned already, you could also use the Django authorization groups.

Quote from the Django documentation: “ Beyond permissions, groups are a convenient way to categorize users to give them some label, or extended functionality.”

The best solution depends on your requirements and current circumstances. In general it is good to follow best practices and the Django documentation is, among others, a good source for that.

1 Like

Thank you vary much for your reply. It helped me.

Thank you very much for your reply. It helped me.