Django upgrade from 1.10 to 1.11 DeprecationWarning

怎甘沉沦 提交于 2020-08-20 11:46:16

问题


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

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

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)   

回答1:


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.



来源:https://stackoverflow.com/questions/52578687/django-upgrade-from-1-10-to-1-11-deprecationwarning

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!