def set_password(self, raw_password): if not raw_password: return None hash_password = hashers.make_password(raw_password) self.password = hash_password self.save(update_fields=['password'])
def update_password(self, raw_password): # # 若不满足条件 直接抛出异常 # assert raw_password if not raw_password: return None hash_password = hashers.make_password(raw_password) self.password = hash_password self.save(update_fields=['password'])
def __init__(self, *args, **kwargs): if 'password' in kwargs: hash_password = hashers.make_password(kwargs['password']) kwargs['password'] = hash_password super(FrontUserModel, self).__init__(*args, **kwargs)
def password(self,raw_password): self._password = hashers.make_password(raw_password) self.save()