I completed finish my Django E-commerce web-application. And now I want to add the facility of customer roles(admin,staff,merchant,customer). I’m having problems configuring this with my project. I’d really appreciate if someone can help me through the process. I am sharing the details of project.
My existing Customer model
class Customer(models.Model):
user=models.OneToOneField(User,on_delete=models.CASCADE)
# user=models.OneToOneField(User,on_delete=models.CASCADE) -change I made to add CustomUser model
phone=models.CharField(max_length=10)
city = models.TextField(max_length=30)
state = models.TextField(max_length=30)
def __str__(self):
return self.user.username
My CustomerUser model that I want to introduce in my project
class CustomUser(AbstractUser):
ROLES=(
('admin', 'Admin'),
('staff', 'Staff'),
('merchant', 'Merchant'),
('user', 'User'),
)
role = models.CharField(max_length=8,choices=ROLES,default='Customer')
def is_admin(self):
return self.role == 'admin'
def is_staff(self):
return self.role == 'staff'
def is_merchant(self):
return self.role == 'merchant'
The login, logout and registration stopped working as soon as I added this CustomUser model into my project.
3