I think you need to use (USER_TYPES) in your (CustomUser Model), I don’t know what is your CustomUser Model Fields.
Also you can rely on one Model(CustomUser) for every users and use (is_active) to prevent any user from login to your application and use (USER_TYPES) as :
choices.py file
OWNER = "owner"
CLIENT = "client"
ADMIN = 'admin'
VENDOR = 'vendor'
EDITOR = 'editor'
MANAGER = 'manager'
EMPLOYEE = 'employee'
REPRESENTATIVE = 'rep'
DRIVER = 'driver'
USER_TYPES = (
(OWNER, "Owner"),
(MANAGER, "Manager"),
(ADMIN, "Admin"),
(EMPLOYEE, "Employee"),
(EDITOR, "Editor"),
(VENDOR, "Vendor"),
(CLIENT, "Client"),
(REPRESENTATIVE, "Representative"),
(DRIVER, "Driver"),
)
models.py for CustomUser
from django.contrib.auth.models import AbstractUser
class CustomUser(AbstractUser):
# add additional fields in here
mobile1 = models.CharField(max_length=30, unique=True)
mobile2 = models.CharField(max_length=30, blank=True, null=True)
phone = models.CharField(max_length=30, blank=True, null=True)
role = models.CharField(
max_length=25, choices=choices.USER_TYPES, default=choices.CLIENT
)
The above code is a sample, you can modify it to meet your needs.
By using (USER_TYPES) you can make any user with a specific role to create or update (course model) also you can prevent any user by doing a simple thing in your template
{% if request.user.role == 'admin' %}
... Do something for admin users
{% elif request.user.role == 'employee' %}
... Do something for employees users
{% elif request.user.role == 'editor' %}
... Do something for editors users
{% endif %}
Or you can make a decorator for a specific view function (to prevent some users with a specific role) to access your (creation course or update course)
Or you can use Django Groups to make such mission