[Answered ]-Raise FieldError( django.core.exceptions.FieldError: Cannot resolve keyword 'is_active' into field

1👍

Since you are specifying the custom User model, the is_active is a required field for the AbstractBaseUser model in Django.

You should add it in the Usuario model, like so:

class Usuario(AbstractBaseUser):
    centro = models.ForeignKey(Centro, on_delete=models.CASCADE, verbose_name='Centro o Unidad', blank=True, null=True)
    telefono = models.CharField(max_length=100, unique=True, verbose_name='Teléfono')
    rut = models.CharField(max_length=100, unique=True, verbose_name='RUT')
    profesion = models.CharField(max_length=150, verbose_name='Profesión')
    cargo = models.CharField(max_length=150, verbose_name='Cargo')
    nacionalidad = models.CharField(max_length=100, verbose_name='Nacionalidad')
    sexo = models.CharField(max_length=10, choices=SEXO_CHOICES ,verbose_name='Sexo')
    fecha_nacimiento = models.DateField(auto_now=False, auto_now_add=False,verbose_name='Fecha de nacimiento', blank=True, null=True)
    imagen_perfil = models.ImageField(upload_to='perfil/', verbose_name='Imágen de Perfil', max_length='255', blank=True, null=True)
    direccion = models.CharField(max_length=250, blank=True, null=True, verbose_name='Dirección')
    is_active = models.BooleanField(default=True)
    objects = UsuarioManager()

    USERNAME_FIELD = 'email'
    REQUIRED_FIELDS = ['email', 'nombre']

    def __str__(self):
        return self.first_name
    
    def get_email_user(self):
        return self.email.lower()
    
    def save(self, *args, **kwargs):
        self.email = self.email.lower()
        return super(Usuario, self).save(*args, **kwargs)
    
    def has_perm(self, perm, obj = None):
        return True
    
    def has_module_perms(self, app_label):
        return True
    
    @property
    def is_staff(self):
        return self.is_staff

Then run migration commands.

Leave a comment