问题
I have a custom User in my django app. And when I submit an email to reset password in the the built in password reset form, I get the following error
FieldError at /password_reset/ Cannot resolve keyword 'is_active' into field. Choices are: active, address, admin, bio, company_category, company_desc, company_name, company_site, country, designation, email, first_name, grad_year, id, last_login, last_name, linkedin, logentry, markets, no_employees, password, phone, photo, resume, staff, technologies, university
My custom user model and model manager are as follows:
# ----------------------------- USER MANAGER -----------------------------
class UserManager(BaseUserManager):
def create_user(self, email, password=None, is_active=True, is_staff=False, is_admin=False):
if not email:
raise ValueError("Users must have an email address")
if not password:
raise ValueError("Users must have a password")
user_obj = self.model(
email = self.normalize_email(email),
)
user_obj.staff = is_staff
user_obj.admin = is_admin
user_obj.active = is_active
user_obj.set_password(password)
user_obj.save(using=self._db)
return user_obj
def create_staffuser(self, email, password=None):
user = self.create_user(
email,
password=password,
staff=True,
admin=True
)
return user
def create_superuser(self, email, password=None):
user = self.create_user(
email,
password=password,
is_staff=True,
is_admin=True
)
return user
# ----------------------------- CUSTOM USER -----------------------------
class User(AbstractBaseUser):
email = models.EmailField(max_length=255, unique=True)
first_name = models.CharField(max_length=255)
last_name = models.CharField(max_length=255)
resume = models.FileField(upload_to='res/', blank=True, null=True, verbose_name='resume')
photo = models.ImageField(upload_to='pi/', default='img/default.png', blank=True, null=True)
bio = models.CharField(max_length=1000)
designation = models.CharField(max_length=255)
university = models.CharField(max_length=255)
company_name = models.CharField(max_length=255)
grad_year = models.IntegerField(blank=False, null=True)
phone = models.CharField(max_length=255)
address = models.CharField(max_length=255)
country = models.CharField(max_length=255)
company_category = models.CharField(max_length=255, blank=False)
company_desc = models.CharField(max_length=800, blank=False)
company_site = models.CharField(max_length=255)
no_employees = models.IntegerField(blank=False, null=True)
technologies = models.CharField(max_length=255, blank=False)
markets = models.CharField(max_length=255, blank=False)
linkedin = models.CharField(max_length=255, blank=False)
active = models.BooleanField(default=True)
staff = models.BooleanField(default=False)
admin = models.BooleanField(default=False)
USERNAME_FIELD = 'email'
REQUIRED_FIELDS = [] #python manage.py createsuperuser asks for these fields
objects = UserManager()
def __str__(self):
return self.email
def get_full_name(self):
if self.full_name:
return self.full_name
else:
return self.email
def get_short_name(self):
return self.email
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.staff
@property
def is_admin(self):
return self.admin
@property
def is_active(self):
return self.active
How can this be solved?
来源:https://stackoverflow.com/questions/62177852/field-error-during-password-reset-in-django-custom-user