本文整理匯總了Python中models.user.UserModel.save_to_db方法的典型用法代碼示例。如果您正苦於以下問題:Python UserModel.save_to_db方法的具體用法?Python UserModel.save_to_db怎麽用?Python UserModel.save_to_db使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類models.user.UserModel
的用法示例。
在下文中一共展示了UserModel.save_to_db方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: post
# 需要導入模塊: from models.user import UserModel [as 別名]
# 或者: from models.user.UserModel import save_to_db [as 別名]
def post(self):
data = UserRegister.parser.parse_args()
if UserModel.find_by_username(data['username']):
return {"message": "User with that username already exists."}, 400
user = UserModel(**data)
user.save_to_db()
return {"message": "User created successfully."}, 201
示例2: post
# 需要導入模塊: from models.user import UserModel [as 別名]
# 或者: from models.user.UserModel import save_to_db [as 別名]
def post(self):
data = _user_parser.parse_args()
if UserModel.find_by_username(data['username']):
return {"message": "A user with that username already exists"}, 400
user = UserModel(data['username'], data['password'])
user.save_to_db()
return {"message": "User created successfully."}, 201
示例3: test_crud
# 需要導入模塊: from models.user import UserModel [as 別名]
# 或者: from models.user.UserModel import save_to_db [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")