Hey everyone! I just finished my Django e-commerce project and now I want to add different user roles like admin, staff, merchant, and customer. But I’m stuck and could use some help.
I’ve got a Customer model that looks like this:
class Customer(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE)
contact = models.CharField(max_length=10)
location = models.TextField(max_length=30)
region = models.TextField(max_length=30)
def __str__(self):
return self.user.username
I tried to add a CustomUser model:
class CustomUser(AbstractUser):
ROLE_CHOICES = (
('admin', 'Admin'),
('staff', 'Staff'),
('merchant', 'Merchant'),
('regular', 'Regular'),
)
role = models.CharField(max_length=8, choices=ROLE_CHOICES, default='Regular')
def is_administrator(self):
return self.role == 'admin'
def is_employee(self):
return self.role == 'staff'
def is_seller(self):
return self.role == 'merchant'
But now my login, logout, and registration aren’t working. Any ideas on how to fix this and get the user roles working? Thanks!