Managing Multiple Types of User with Custom Permissions

I’m facing issues with managing different types of users. And need to customize the admin panel for each users having custom permission. This is my first major project and do not have any mentor to guide me.

Following are the models, I’m working with. The actual models have more fields.

class User(AbstractUser):
    '''
    Regional Admin and Admin can login to the admin panel.
    Regional Admin can only access the nodes data of regions they are assigned to.
    '''
    class UserTypeChoices(models.TextChoices):
        ADMIN = 'ADMIN', 'Admin'
        REGIONAL_ADMIN = 'REGIONAL_ADMIN', 'Regional Admin'
        NORMAL_USER = 'NORMAL_USER', 'Noramal User'

    email = models.EmailField(unique=True, validators=[EmailValidator(message="Invalid Email Address")])
    user_type = models.CharField(max_length=20, choices=UserTypeChoices.choices, default=UserTypeChoices.NORMAL_USER)

    def __str__(self) -> str:
        return self.username

# Country Model
class Country(models.Model):
    name = models.CharField(max_length=100, unique=True)
    population = models.PositiveBigIntegerField(validators=[MinValueValidator(0)], default=0)

    class Meta:
        verbose_name_plural = "Countries"

    def __str__(self) -> str:
        return self.name

# Each country might be divided into one or more zones
class Region(models.Model):
    country = models.ForeignKey(Country, on_delete=models.CASCADE)
    name = models.CharField(max_length=100) # East West North South

    def __str__(self) -> str:
        return self.name

# Each nodes represents some point in a particular region
class Node(models.Model):
    region = models.ForeignKey(Region, on_delete=models.CASCADE)
    name = models.CharField(max_length=100)
    length = models.FloatField(validators=[MinValueValidator(0)])

    def __str__(self) -> str:
        return self.name

The Admin here is the super user and regional admin is a staff user and can login to the admin panel. Each regional user can access region wise data of the Node.

I want to relate the Regions with Users.

Let there are four regions in the region table: East, West, North and South and Each node is related to one of the regions.

If the regional user has the access to a particular region he can perform CRUD operations on the Nodes in that particular regions. One Regional Admin can have access to the multiple regions.

For example if the regional user has the permission to access nodes in East and North regions, he can perform CRUD operations on nodes in East and North region.

I was learning about creating Custom Permission for each types of users and I can create views and check permission easily.

But I want these editing options in the Admin panel.Preformatted text

There are a set of ModelAdmin methods that you can override to provide these facilities. They generally have a name in the form has_..._permission. You’ll probably also need to override the get_queryset method, and there may be other methods you need to override to make this work the way you want.

I’ll also point out this from the official Django admin site docs.

The admin’s recommended use is limited to an organization’s internal management tool. It’s not intended for building your entire front end around.

and

If you need to provide a more process-centric interface that abstracts away the implementation details of database tables and fields, then it’s probably time to write your own views.

It’s actually going to be easier to implement this in your own views than ensuring that you’ve got all the overridden methods correct in the admin.

Thank you for the guidance sir.