首页 文章

如何正确扩展django用户模型

提问于
浏览
2

我正在尝试使用其他字段和功能来扩展默认的Django的身份验证模型,因此我决定继续扩展用户模型并编写自己的身份验证后端 .

from django.db import models
from django.utils.translation import ugettext_lazy as _
from django.contrib.auth.models import User


class MyUser(User):
    access_key = models.CharField(_('Acces Key'), max_length=64)

这是一个基本的代码,但在尝试syncdb时,我正在考虑一个谷歌不知道的奇怪错误:

CommandError: One or more models did not validate: core.sldcuser: 'user_ptr' defines a relation with the model 'auth.User', which has been swapped out. Update the relation to point at settings.AUTH_USER_MODEL.

在我的settings.py中,我添加了我想要的内容:

AUTH_USER_MODEL = 'core.MyUser'

有没有人偶然发现这个错误?

或者也许我应该使用一对一的方式,或1t1与代理的混合?

1 回答

相关问题