具有自定义用户模型的django auth ldap [英] django auth ldap with custom user model

查看:134
本文介绍了具有自定义用户模型的django auth ldap的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将django auth ldap(v1.1.7)与自定义用户模型一起使用,尽管我已经处理了所有其他事项,但仍然遇到熟悉的错误消息,我只是不知道该怎么做.修复.

I'm trying to use django auth ldap (v1.1.7) with a custom user model and, while I have everything else taken care of, I still run into a familiar error message that I just don't know how to fix.

运行python manage.py syncdb返回:

CommandError: One or more models did not validate:
django_auth_ldap.testprofile: 'user' defines a relation with the model 'auth.Use
r', which has been swapped out. Update the relation to point at settings.AUTH_US
ER_MODEL.

我的问题是-在哪里可以找到django_auth_ldap.testprofile并更新该关系以解决此问题?

My question here is - where can I find django_auth_ldap.testprofile and update the relation, to fix the issue?

预先感谢您的帮助.

LE:好吧,经过一番搜索,我发现此测试配置文件位于django_auth_ldap/models.py中,并得到以下信息:我搜索了我的文件的 all ,并找到了已修改的文件它指向设置.AUTH_USER_MODEL,仍然收到相同的错误.

L.E.: Ok, after a little googleing, i found out that this testprofile is located in django_auth_ldap/models.py and get this: I searched through all of my files and found the file, modified it to point to settings.AUTH_USER_MODEL and still I receive the same error.

有人可以帮我解决这个问题吗?

Can anyone please help me out with this issue?

推荐答案

这是

This is the part of django_auth_ldap's models.py -

class TestProfile(models.Model):
    """
    A user profile model for use by unit tests. This has nothing to do with the
    authentication backend itself.
    """
    user = models.OneToOneField('auth.User')  # <-- here is the trouble
    is_special = models.BooleanField(default=False)
    populated = models.BooleanField(default=False)

除非您修复了代码的这一部分并按照

You cannot fix it unless you fix this part of the code and do as said in Django documentation -

应该直接引用用户,而不是直接引用用户 使用django.contrib.auth.get_user_model()建立模型.此方法将 返回当前活动的用户模型-自定义用户模型(如果有的话) 是指定的,否则是User.

Instead of referring to User directly, you should reference the user model using django.contrib.auth.get_user_model(). This method will return the currently active User model – the custom User model if one is specified, or User otherwise.

而且我不建议您自己修改第三方软件包.如果可以,请向开发人员建议更改,或向他们发送请求请求.接受后,更新软件包.

And I wont recommend modifying the 3rd party packages yourself. If you can, go suggest the change to the developer, or send them a pull request. Once it's accepted, update the package.

这篇关于具有自定义用户模型的django auth ldap的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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