python - Django 从 1.10 升级到 1.11 弃用警告
问题描述
我正在尝试将我的项目从 Django 1.10 升级到 1.11:
>>> django.VERSION
(1, 10, 0, 'final', 1)
当我运行 python -Wall manage.py test 时,我收到以下错误消息:
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)
解决方案
这似乎是Python 3.6中Django 的一个问题,不会影响 3.5。从 3.6.x 降级到 3.5.x 应该会导致这种情况消失,尽管从你的帖子中不清楚它是否真的在运行时引起了问题,或者它是否只是一个错误触发的警告。
推荐阅读
- azure-active-directory - Azure 托管标识性能
- python - 使用 matplotlib 和 GetDistTool 设置图例的手动位置
- python - 从 python2 脚本列表输出中删除 u' unicode
- vue.js - Nuxt/Vue 路由参数更新元标题
- excel - 巴士舱单摘要页面公式(列出有开放座位的巴士)
- azure - Azure DevOps “成功”部署了 FunctionApp,但未进行任何更改
- java - 将 Java 和 Prolog 与 JPL 连接时出现问题
- python - 在 Beautiful Soup 中使用 find 函数时返回 NoneType 值
- r - 如何使用“插入符号”库在 R 中加载数据?
- swift - 在 Swift 中,如何在由结构对象数组组成的字典中进行搜索?