Estoy intentando crear un usuario personalizado, he guardado los modelos sin ningún problema pero no puedo llegar a ejecutarlo con exito, al usar el comando py manage.py createsuperuser , me lanza el siguiente error y no encuentro el 'email' al que se refiere:
raise TypeError("%s() got an unexpected keyword argument '%s'" % (cls.name, kwarg)) TypeError: CustomUser() got an unexpected keyword argument 'email'
ACLARO: mi app(Usuario) esta registrada en la settigns.py
y tambien :
AUTH_USER_MODEL = 'Usuario.CustomUser'
Aqui os dejo mi models.py
from django.db import models
from django.contrib.auth.models import AbstractBaseUser, BaseUserManager, UserManager
# Create your models here.
#PRUEBA DE MODELOS PARA USAURIO PERZONALIZADO
class CustomUser(AbstractBaseUser):
#THE FIELDS OF THE USER MODEL
id = models.AutoField(primary_key=True)
username = models.CharField(max_length=100, unique=True)
Name = models.CharField(max_length=100)
Lastname = models.CharField(max_length=100, blank=True, null=True)
Email = models.EmailField(unique=True, max_length=250)
PhoneNumber = models.IntegerField()
User_active = models.BooleanField(default=True)
User_admin = models.BooleanField(default=False)
Objects = UserManager()
def __str__(self):
return self.username +","+ self.Name +","+ self.Lastname +","+ self.Email +","+ str(self.PhoneNumber)
USERNAME_FIELD = 'username'
REQUIRED_FIELD = ['Name', 'Lastname', 'Email', 'PhoneNumber']
def has_perm(self, perm, obj=None):
return True
def has_module_perm(self, app_label):
return True
@property
def is_staff(self):
return self.User_admin
class UserManager(BaseUserManager):
def create_user(self, username, Name, Lastname, PhoneNumber, Email, password= None):
if not Email:
raise ValueError("Es obligatorio ingresar un correo")
User = self.model(
username = username,
Name = Name,
Lastname = Lastname,
Email = self.normalize_email(Email)
)
User.set_password(password)
User.save()
return User
def create_superuser(self, username, Name, Lastname, PhoneNumber, Email, password):
user = self.create_user(
Email="",
username = username,
Name = Name,
Lastname = Lastname,
)
user.User_admin = True
user.save()
return user