I created a custom user model by name Shop into django and when i create the super user with this command python manage.py createsuperuser it creates the super user but still setting is_staff to False, is_superuser to False and also is_admin to false. when i try to login to the admin panel using the user i get the error that my credentials are not correct.I have tried everything and research as much as i can but to no avail. I need help this is my code
from django.db import models
from django.contrib.auth.models import AbstractBaseUser, BaseUserManager,
PermissionsMixin
from django.utils.text import slugify
from django.utils.crypto import get_random_string # generates a random string
from django.db import IntegrityError
class UserManager(BaseUserManager):
def create_user(self, email, shop_name='', mall_name='', password=None, **kwargs):
if not email:
raise ValueError('You must enter an email address')
user = self.model(email=self.normalize_email(email), shop_name=shop_name, mall_name=mall_name)
user.set_password(password)
user.save(using=self._db)
return user
def create_superuser(self,email, password):
user = self.create_user(
email,
password=password,
is_admin=True,
is_superuser=True,
is_staff=True
)
user.save(using=self._db)
return user
list_of_malls = [('Dubai mall', 'Dubai mall'),
('Dubai Festival City Mall','Dubai Festival City Mall'),
('Ibn Battuta Mall', 'Ibn Battuta Mall')
]
class Shop(AbstractBaseUser, PermissionsMixin):
email = models.EmailField(unique=True, blank=False)
date_joined = models.DateTimeField(auto_now_add=True)
is_active = models.BooleanField(default=True)
is_superuser = models.BooleanField(default=False)
is_admin = models.BooleanField(default=False)
shop_name = models.CharField(max_length=50, null=True)
mall_name = models.CharField(choices=list_of_malls, max_length=50, null=True)
slug = models.SlugField(max_length=50, unique=True)
is_staff = models.BooleanField(default=False)
objects = UserManager()
USERNAME_FIELD = 'email'
REQUIRED_FIELDS = []
def save(self, *args, **kwargs):
if not self.slug:
try:
self.slug = slugify(self.shop_name + " shop " + get_random_string(20) )
super(Shop, self).save(*args, **kwargs)
#add shop_name with 10 randomly generated characters to create slug
except IntegrityError:
pass
def __str__(self):
return self.email