Django custom Permission & Groups Table / Model


I was working on a project where I need to use Django auth with the custom user model using AbstractBaseUser

class CustomUser(AbstractBaseUser):
    email = models.EmailField(unique=True)
    is_active = models.BooleanField(default=True)
    is_staff = models.BooleanField(default=False)

    objects = CustomUserManager()

    USERNAME_FIELD = 'email'

But I also don’t want to use inbuild groups & permissions table
I need to create my groups/roles & permissions, so I made something like as below.

class Role(models.Model):
    name = models.CharField(max_length=100, unique=True)

class Permission(models.Model):
    name = models.CharField(max_length=100, unique=True)

class RolePermission(models.Model):
    role_id = models.IntegerField()
    permission_id = models.IntegerField()

How do I create my own Role & Permission Table with my custom user model and implement other features in the permission with custom context_processor? and other functions?

Similar: custom django-user object has no attribute 'has_module_perms' - Stack Overflow , if you could give some code it would be helpful

Where I don’t want to use inbuild permissions with PermissionsMixin!
And also need an admin portal how we register these custom user, custom permissions & custom role models?

or how can I remove the default adding permissions in Django for each model?

Note: I have tried this Customizing authentication in Django | Django documentation | Django
But it threw error when I tried to access /admin portal - ‘CustomUser’ object has no attribute ‘get_permissions’




What benefit do you hope to achieve by expending effort to rewrite functionality that is already provided for you within Django?

It’s fine that I can use inbuild PermissionsMixin but, I don’t want to have a default permissions added in permission table and also I want to add few more fields in groups table and permissions table

Am Planning to use inbuild Django permissions & groups.

I have a couple of more questions

  1. Am using a decorator with permission, my requirement is I need to add permission decorators for each view function and that should get logged-in user groups & check what are all permissions associated with that groups, but the below code @ permission_required will do I believe it checks only permissions assigned to users not from group permissions correct? if so do I need to write custom decorator?
    suggest me some idea.
from django.contrib.auth.decorators import permission_required

def my_view(request): 
  1. the same question for UI template, to show form based on permissions, is it tied up with user permission or group permission
    I need only group permission
{% if %}

do i need to write custom context processed for the logic
check based on logged in user groups and check the group permissions associated and show the form in UI

  1. and also check permission by user permission or group permission

suggest some standard way