通过TokenAuthentication中的AUTH_USER_MODEL使用自定义模型而不是用户实例

时间:2020-07-12 14:38:03

标签: authentication django-rest-framework django-admin token django-signals

我正在使用TokenTokenAuthentication来为创建的每个用户创建令牌。我正在使用自定义模型(Utilisateur)和AUTH_USER_MODEL。 该模型需要set_password字段,根据我在网上看到的内容,将其设置为None,我尝试设置默认值,但是当我尝试连接到django管理页面以验证令牌是否确实存在时,我仍然收到相同的错误通过令牌表为每个新用户创建的。 任何人都可以帮助我确定正确的配置,因为未创建令牌。

当我尝试连接到django管理页面时,错误是 'NoneType'对象不可调用 enter image description here

models.py代码

\0

signals.py文件代码

ccbf4f0a52fd5ac59e18448ebadf2ef37c62f54f

和settings.py文件

from django.contrib.auth.models import UserManager

class Utilisateur(models.Model):
    id = models.BigAutoField(primary_key=True)
    matricule = models.CharField(unique=True, max_length=5, blank=True, null=True)
    user_name = models.CharField(unique=True, max_length=30, blank=True, null=True)
    password = models.CharField(max_length=30, blank=True, null=True)
    nom = models.CharField(max_length=20, blank=True, null=True)
    prenom = models.CharField(max_length=20, blank=True, null=True)
    tel = models.CharField(unique=True, max_length=10, blank=True, null=True)
    email = models.CharField(unique=True, max_length=300, blank=True, null=True)
    fonction = models.CharField(max_length=50)
    entreprise = models.CharField(max_length=20, blank=True, null=True)
    id_type_utilisateur = models.ForeignKey(TypeUtilisateur, models.DO_NOTHING, db_column='id_type_utilisateur')
    id_site = models.ForeignKey(Site, models.DO_NOTHING, db_column='id_site')

    REQUIRED_FIELDS = ['password']
    USERNAME_FIELD = 'user_name'
    is_anonymous = False
    is_authenticated = False
    is_active = False
    set_password = None

    objects = UserManager()

    class Meta:
        managed = False
        db_table = 'utilisateur' 

0 个答案:

没有答案
相关问题