I would like to separate users of my Django app in two classes :
- Admin (users that use Django admin) - inherit from AbstractUser
- User (customers users) - inherit from AbstractBaseUser
I want to separate this two kinds of users because all fields of AbstractUser
(is_staff
, is_superuser
, groups
, permissions
) are useless for my customer users and for permissions and group, I just want to implement something different. That why, I want to use AbstractBaseUser
.
But for django admin users, AbstractUser
class, it's just perfect and particularly with permissions feature.
class Admin(AbstractUser):
pass
class Customer(AbstractBaseUser):
pass
But now, is there a way to precise the User model used Admin
for the django admin only?
And use the Customer
model for the rest of my apps.
Did I have to implement this from scratch :
class MyUser(AbstractBaseUser):
username = models.CharField(max_length=30, unique=True)
first_name = models.CharField(max_length=30)
last_name = models.CharField(max_length=30)
email = models.EmailField()
is_active = models.BooleanField(default=False)
class Admin(MyUser, PermissionsMixin):
is_staff = models.BooleanField(default=True)
class Customer(MyUser):
# specific fields
pass
With this implementation, if I set AUTH_USER_MODEL
to User
, permissions will not work because User
has no permissions
, is_superuser
and is_staff
fields.
And if a set it to Admin
, I will not be able to authenticate Customers
with django.contrib.auth
.
So guys do you have a solution to this issue?