我正在尝试将项目从Django 1.10升级到1.11:
>>> django.VERSION
(1, 10, 0, 'final', 1)
当我运行python -Wall manage.py测试时,出现以下错误消息:
C:\Users\Environments\lib\site-packages\django\contrib\auth\base_user.py:52: DeprecationWarning: __class__ not set defining 'AbstractBaseUser' as <class 'django.contrib.auth.base_user.AbstractBaseUser'>. Was __classcell__ propagated to type.__new__? class AbstractBaseUser(models.Model):
我环顾四周,但找不到解决此投诉的解决方案。鉴于我正在扩展用户类,因此这不应仅针对我的项目。那么,有没有人找到解决此问题的方法?
class User(AbstractBaseUser, PermissionsMixin):
"""
Custom user class
"""
USER_TYPE = (
('owner', 'Owner'),
('developer', 'Developer'),
('general contractor', 'General Contractor'),
('general contractor\'s employee', 'General Contractor\'s Employee'),
('consultant', 'Consultant'),
('subcontractor', 'Subcontractor'),
('home owners', 'Home Owners'),
('construction financier', 'Construction Financier'),
('lawyer', 'Lawyer'),
('accountant', 'Accountant'),
)
email = models.EmailField(verbose_name = 'email address',unique = True, db_index = True)
# email is the unique field that can be used for identification purposes
joined = models.DateTimeField(auto_now_add = True)
is_active = models.BooleanField(default = True)
is_admin = models.BooleanField(default = False)
is_superuser = models.BooleanField(default = False)
#is_staff = models.BooleanField(default = False)
user_type = models.CharField(max_length = 30, choices = USER_TYPE)
group = models.ManyToManyField(Group, related_name = 'users')
permission = models.ManyToManyField(Permission, related_name = 'users')
objects = CustomUserManager()
# Added:
#company = models.ForeignKey(Company, related_name = 'users')
USERNAME_FIELD = 'email' # the unique identifier (mandatory) The filed must have unique=True set in its definition (see above)
def get_full_name(self):
return self.email
def get_short_name(self):
return self.email
def has_perm(self, perm, obj=None):
''' Does the user have a specific permission'''
return True # This may need to be changed depending on the object we want to find permission for
def has_module_perms(self, app_label):
''' Does the user have permission to view the app 'app_label'? The default answer is yes.
This may be modified later on. '''
return True
@property
def is_staff(self):
''' Is the user a member of staff? '''
return self.is_admin
def __unicode__(self):
return '{user_email}, {user_title} joined on {joined_date}'.format(user_email = self.email,
user_title = self.user_type,
joined_date = self.joined)
def __str__(self):
return '{user_email}, {user_title} joined on {joined_date}'.format(user_email = self.email,
user_title = self.user_type,
joined_date = self.joined)
答案 0 :(得分:0)
这似乎是an issue with Django in Python 3.6的doesn't impact 3.5。从3.6.x降级到3.5.x应该会导致这种情况消失,尽管从您的帖子中还不清楚它实际上是在运行时引起问题还是仅仅是错误触发的警告。