Django从1.10升级到1.11弃用警告 [英] Django upgrade from 1.10 to 1.11 DeprecationWarning

查看:46
本文介绍了Django从1.10升级到1.11弃用警告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将项目从Django 1.10升级到1.11:

I am trying to upgrade my project from Django 1.10 to 1.11:

>>> django.VERSION
(1, 10, 0, 'final', 1)

当我运行python -Wall manage.py测试时,收到以下错误消息:

When I run python -Wall manage.py test, I get the following error message:

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):

我环顾四周,但找不到解决此投诉的解决方案.鉴于我正在扩展用户类,因此这不应该是我的项目所特有的.那么,有没有人找到解决此问题的方法?

I have looked around but could not find a solution to address this complaint. Given that I am extending the user class, this should not be particular to my project. So, has anyone found a way to resolve this?

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)   

推荐答案

这似乎是 doesn不会影响3.5 .从3.6.x降级到3.5.x应该会导致这种情况消失,尽管您的帖子尚不清楚它是否实际上是在运行时引起问题,还是仅仅是错误触发的警告.

This appears to be an issue with Django in Python 3.6 that doesn't impact 3.5. Downgrading from 3.6.x to 3.5.x should result in this going away, though it's not clear from your post whether it's actually causing problems at runtime or whether it's just an incorrectly triggered warning.

这篇关于Django从1.10升级到1.11弃用警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆