# Django custom Permission & Groups Table / Model

**URL:** <https://forum.djangoproject.com/t/django-custom-permission-groups-table-model/30129>\
**Category:** Forms & APIs\
**Created:** [April 13, 2024, 5:27pm UTC](https://forum.djangoproject.com/t/django-custom-permission-groups-table-model/30129 "2024-04-13T17:27:15Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![vinothrajs](https://avatars.discourse-cdn.com/v4/letter/v/65b543/32.png) [@vinothrajs](https://forum.djangoproject.com/u/vinothrajs)\
**Post date:** [April 13, 2024, 5:27pm UTC](https://forum.djangoproject.com/t/django-custom-permission-groups-table-model/30129/1 "2024-04-13T17:27:15Z")

</div>

Hi,

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

```auto
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.

```auto
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](https://stackoverflow.com/questions/31370333/custom-django-user-object-has-no-attribute-has-module-perms) , 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](https://docs.djangoproject.com/en/5.0/topics/auth/customizing/#a-full-example)  
But it threw error when I tried to access /admin portal - ‘CustomUser’ object has no attribute ‘get\_permissions’

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [April 13, 2024, 6:43pm UTC](https://forum.djangoproject.com/t/django-custom-permission-groups-table-model/30129/2 "2024-04-13T18:43:57Z")

</div>

> [@vinothrajs](#):
>
> But I also don’t want to use inbuild groups & permissions table

Why?

> [@vinothrajs](#):
>
> Where I don’t want to use inbuild permissions with `PermissionsMixin`!

Why?

> [@vinothrajs](#):
>
> or how can I remove the default adding permissions in Django for each model?

Why?

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

---

<div class="post-metadata">

**Author:** ![vinothrajs](https://avatars.discourse-cdn.com/v4/letter/v/65b543/32.png) [@vinothrajs](https://forum.djangoproject.com/u/vinothrajs)\
**Post date:** [April 13, 2024, 7:03pm UTC](https://forum.djangoproject.com/t/django-custom-permission-groups-table-model/30129/3 "2024-04-13T19:03:19Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![vinothrajs](https://avatars.discourse-cdn.com/v4/letter/v/65b543/32.png) [@vinothrajs](https://forum.djangoproject.com/u/vinothrajs)\
**Post date:** [April 14, 2024, 6:04pm UTC](https://forum.djangoproject.com/t/django-custom-permission-groups-table-model/30129/4 "2024-04-14T18:04:16Z")

</div>

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.

```auto
from django.contrib.auth.decorators import permission_required

@permission_required("demo.add_users")
def my_view(request): 
	pass

```

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

```auto
{% if perms.foo.add_vote %}

```

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

```auto
request.user.has_perm("blog.set_published_status")

```

suggest some standard way

Thanks!
