Python 扩展MongoEngine用户文档是一种不好的做法吗?
我正在使用MongoEngine集成MongoDB。它提供了标准pymongo设置所缺乏的身份验证和会话支持 在常规的django auth中,扩展用户模型被认为是不好的做法,因为不能保证它在任何地方都能正确使用。Python 扩展MongoEngine用户文档是一种不好的做法吗?,python,django,mongodb,mongoengine,nosql,Python,Django,Mongodb,Mongoengine,Nosql,我正在使用MongoEngine集成MongoDB。它提供了标准pymongo设置所缺乏的身份验证和会话支持 在常规的django auth中,扩展用户模型被认为是不好的做法,因为不能保证它在任何地方都能正确使用。mongoengine.django.auth是否就是这种情况 如果这被认为是不好的做法,那么附加单独的用户配置文件的最佳方式是什么?Django具有指定AUTH\u PROFILE\u模块的机制。这在MongoEngine中也受支持吗,或者我应该手动执行查找吗?我们只是扩展了用户类
mongoengine.django.auth是否就是这种情况
如果这被认为是不好的做法,那么附加单独的用户配置文件的最佳方式是什么?Django具有指定AUTH\u PROFILE\u模块的机制。这在MongoEngine中也受支持吗,或者我应该手动执行查找吗?我们只是扩展了用户类
class User(MongoEngineUser):
def __eq__(self, other):
if type(other) is User:
return other.id == self.id
return False
def __ne__(self, other):
return not self.__eq__(other)
def create_profile(self, *args, **kwargs):
profile = Profile(user=self, *args, **kwargs)
return profile
def get_profile(self):
try:
profile = Profile.objects.get(user=self)
except DoesNotExist:
profile = Profile(user=self)
profile.save()
return profile
def get_str_id(self):
return str(self.id)
@classmethod
def create_user(cls, username, password, email=None):
"""Create (and save) a new user with the given username, password and
email address.
"""
now = datetime.datetime.now()
# Normalize the address by lowercasing the domain part of the email
# address.
# Not sure why we'r allowing null email when its not allowed in django
if email is not None:
try:
email_name, domain_part = email.strip().split('@', 1)
except ValueError:
pass
else:
email = '@'.join([email_name, domain_part.lower()])
user = User(username=username, email=email, date_joined=now)
user.set_password(password)
user.save()
return user
MongoEngine现在支持AUTH\u PROFILE\u模块
在Django 1.5中,您现在可以使用可配置的用户对象,因此这是不使用单独对象的一个很好的理由,我认为可以肯定地说,如果您使用Django,扩展用户模型不再被认为是不好的做法。您可以编辑您的答案并添加一个解释这一点的链接吗?我似乎找不到关于它的任何信息。只需检查上的代码并与上的代码进行比较,实际上你可以自己做,就像**注意:这不是使用缓存**不,这不起作用,因为mongoengine.django.auth.User
当前没有实现get\u profile()方法。
AUTH_USER_MODEL = 'myapp.MyUser'