우리는 단지 확장 사용자 클래스입니다. 그와 내가 말을하는 것이 안전하다고 생각 별도의 객체를 사용하지 않는 것이 큰 이유 그래서
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
답변을 수정하고 이것을 설명하는 링크를 추가 할 수 있습니까? 그것에 관한 정보를 찾을 수없는 것 같습니다. – Soviut
[mongoengine] (https://github.com/MongoEngine/mongoengine/blob/master/mongoengine/django/auth.py#L37-130)의 코드를 확인하고 [django] (https : //github.com/django/django/blob/master/django/contrib/auth/models.py#L379-407) infact는 [this]와 같이 스스로 할 수 있습니다 (https://github.com/ruandao/mongoengine_django_contrib_auth). /blob/master/models.py#L134-163) **주의 : 이것은 캐시를 사용하지 않았습니다 ** – ruandao