本文整理汇总了Python中models.user.UserModel.find_by_id方法的典型用法代码示例。如果您正苦于以下问题:Python UserModel.find_by_id方法的具体用法?Python UserModel.find_by_id怎么用?Python UserModel.find_by_id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.user.UserModel
的用法示例。
在下文中一共展示了UserModel.find_by_id方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_crud
# 需要导入模块: from models.user import UserModel [as 别名]
# 或者: from models.user.UserModel import find_by_id [as 别名]
def test_crud(self):
with self.app_context():
user = UserModel('test', 'abcd')
self.assertIsNone(UserModel.find_by_username('test'), "Found an user with name 'test' before save_to_db")
self.assertIsNone(UserModel.find_by_id(1), "Found an user with id '1' before save_to_db")
user.save_to_db()
self.assertIsNotNone(UserModel.find_by_username('test'),
"Did not find an user with name 'test' after save_to_db")
self.assertIsNotNone(UserModel.find_by_id(1), "Did not find an user with id '1' after save_to_db")
示例2: identity
# 需要导入模块: from models.user import UserModel [as 别名]
# 或者: from models.user.UserModel import find_by_id [as 别名]
def identity(payload):
"""
Function that gets called when user has already authenticated, and Flask-JWT verified their authorizations header
is correct.
:param payload: A dictionary with 'identity' , key, which is the user id.
:return: A UserModel object.
"""
user_id = payload['identity']
return UserModel.find_by_id(user_id)
示例3: delete
# 需要导入模块: from models.user import UserModel [as 别名]
# 或者: from models.user.UserModel import find_by_id [as 别名]
def delete(cls, user_id: int):
user = UserModel.find_by_id(user_id)
if not user:
return {'message': 'User Not Found'}, 404
user.delete_from_db()
return {'message': 'User deleted.'}, 200
示例4: get
# 需要导入模块: from models.user import UserModel [as 别名]
# 或者: from models.user.UserModel import find_by_id [as 别名]
def get(cls, user_id: int):
user = UserModel.find_by_id(user_id)
if not user:
return {'message': 'User Not Found'}, 404
return user.json(), 200
示例5: identity
# 需要导入模块: from models.user import UserModel [as 别名]
# 或者: from models.user.UserModel import find_by_id [as 别名]
def identity(payload):
user_id = payload['identity']
return UserModel.find_by_id(user_id)