custom django-user object has no attribute 'has_module_perms'

后端 未结 3 1079
刺人心
刺人心 2021-02-12 07:00

My custom user model for login via email:

class MyUser(AbstractBaseUser):
    id = models.AutoField(primary_key=True)  # AutoField?
    is_superuser = models.Int         


        
3条回答
  •  长情又很酷
    2021-02-12 07:46

    Your User implementation is not providing the mandatory methods to be used with the Admin module.

    See https://docs.djangoproject.com/en/3.0/ref/contrib/admin/#module-django.contrib.admin.

    In your case, add the permissions mixin (PermissionsMixin), as a superclass of your model:

    from django.contrib.auth.models import PermissionsMixin
    
    
    class MyUser(AbstractBaseUser, PermissionsMixin):
         # ...
    

    It is described here : https://docs.djangoproject.com/en/3.0/topics/auth/customizing/#custom-users-and-permissions.

    It works with Django 1.x, 2.x and 3.0.

    EDIT: updated links to django version 3.0

提交回复
热议问题