扩展 MongoEngine 用户文档是不好的做法吗?
我正在使用 MongoEngine 集成 MongoDB。它提供了标准 pymongo 设置所缺乏的身份验证和会话支持。
在常规 django auth 中,扩展 User 模型被认为是不好的做法,因为不能保证它在任何地方都能正确使用。 mongoengine.django.auth
就是这种情况吗?
如果这被认为是不好的做法,那么附加单独的用户配置文件的最佳方法是什么? Django 有指定 AUTH_PROFILE_MODULE 的机制。 MongoEngine 是否也支持此功能,或者我应该手动进行查找?
I'm integrating MongoDB using MongoEngine. It provides auth and session support that a standard pymongo setup would lack.
In regular django auth, it's considered bad practice to extend the User model since there's no guarantee it will be used correctly everywhere. Is this the case with mongoengine.django.auth
?
If it is considered bad practice, what is the best way to attach a separate user profile? Django has mechanisms for specifying an AUTH_PROFILE_MODULE
. Is this supported in MongoEngine as well, or should I be manually doing the lookup?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我们刚刚扩展 User 类。
We just extended the User class.
MongoEngine 现在支持 AUTH_PROFILE_MODULE
https:// github.com/ruandao/mongoengine_django_contrib_auth/blob/master/models.py#L134-163
MongoEngine now supports
AUTH_PROFILE_MODULE
https://github.com/ruandao/mongoengine_django_contrib_auth/blob/master/models.py#L134-163
在 Django 1.5 中,您现在可以使用可配置的用户对象,因此这是不使用单独对象的一个重要原因,并且我认为可以肯定地说,如果您使用 Django <<,扩展用户模型不再被认为是不好的做法。 1.5,但预计会在某个时候升级。在 Django 1.5 中,可配置的用户对象通过以下方式设置:
在 settings.py 中。如果您要更改以前的用户配置,则某些更改会影响集合命名等。如果您还不想升级到 1.5,则可以暂时扩展 User 对象,然后在升级时进一步更新它升级到1.5。
https://docs.djangoproject.com/en/dev/ topic/auth/#auth-custom-user
注意,我还没有亲自在 Django 1.5 w/ MongoEngine 中尝试过这个,但希望它应该支持它。
In Django 1.5 you can now use a configurable user object, so that's a great reason to not use a separate object and I think it's safe to say that it is no longer considered bad practice to extend the User model if you are on Django <1.5 but expecting to upgrade at some point. In Django 1.5, the configurable user object is set with:
in your settings.py. If you are changing from a previous user configuration, there are changes that impact collection naming etc. If you don't want to upgrade to 1.5 just yet, you can extend the User object for now, and then update it further later when you do upgrade to 1.5.
https://docs.djangoproject.com/en/dev/topics/auth/#auth-custom-user
N.B. I have not personally tried this in Django 1.5 w/ MongoEngine, but expect it should support it.