0
I rewrote the User
Django model for CustomUser
using AbstractUSer
adding two booleans, such as is_admin
and is_insurer
.
Moreover, two groups were created programmatically: admin_group
and insurer_group
each with their respective permissions. I am trying to add each group to user type.
In the case:
1 - CustomUser.is_admin
equal to admin_group
,
2 - CustomUser.is_insurer
equal to insurer_group
So as soon as I add the user type, ex: is_admin
for True, this user has access to admin_group
.
I’m trying this way:
py.models:
from django.db import models
from django.contrib.auth.models import AbstractUser, Group, Permission
from django.contrib.contenttypes.models import ContentType
class CustomUser(AbstractUser):
is_admin = models.BooleanField(default=False)
is_insurer = models.BooleanField(default=False)
@property
def insurer(self):
insurer_group = Group.objects.get(name='insurer_group')
self.is_insurer.groups.add(insurer_group)
@property
def admin(self):
admin_group = Group.objects.get(name='admin_group')
self.is_admin.groups.add(insurer_group)
def __str__(self):
return self.username
But I’m getting error:
maximum recursion depth exceeded while calling a Python object
I have tried passing the permission directly on the Customuser model however it will not.