[Django]-How to have multiple user types in django

2πŸ‘

βœ…

It is better to handle it with a field (not with 2 different models) for example you can have something like this:

class User(models.Model) :
    # NEW
    ROLES = (('student', 'Student'), ('teacher', 'Teacher'))
    role = models.CharField(
        max_length=20,
        choices=ROLES,
        default='student'
    )


    national_id = models.CharField(
        max_length=50,
        unique=True,
    )

    name = models.CharField(max_length=50)
    last_name = models.CharField(max_length=50)
    phone_number = models.CharField(max_length=50)

Also, you can use the Django permission model more detail

0πŸ‘

Django has Roles and Groups to categorise users. What is allowed and forbidden is controlled by Permissions. Every User, Role and Group can have different model-specific and view-specific Permissions. The system is quite complex and allows for many different setups. I’d suggest you chek an overview such as this one.

πŸ‘€Jura Brazdil

Leave a comment