本文整理汇总了Python中model.Model.insert方法的典型用法代码示例。如果您正苦于以下问题:Python Model.insert方法的具体用法?Python Model.insert怎么用?Python Model.insert使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类model.Model
的用法示例。
在下文中一共展示了Model.insert方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_get
# 需要导入模块: from model import Model [as 别名]
# 或者: from model.Model import insert [as 别名]
def test_get(self):
'''get函数返回的数据要包含model_name'''
category_model = self.model
model_model = Model()
new_category_id = category_model.insert(test_helper.storage({'title':'cat1'}))
new_model_id = model_model.insert(test_helper.storage({'Categoryid':new_category_id}))
inserted_category = category_model.get(new_category_id)
self.assertEqual(inserted_category.model_name,model_model.table_name)
示例2: test_getAll
# 需要导入模块: from model import Model [as 别名]
# 或者: from model.Model import insert [as 别名]
def test_getAll(self):
'''getAll函数返回的数据只包含model_name,不包含models'''
category_model = self.model
model_model = Model()
new_category_id = category_model.insert(test_helper.storage({'title':'cat1'}))
new_model_id = model_model.insert(test_helper.storage({'Categoryid':new_category_id}))
all_categorys = category_model.getAll()
self.assertEqual(len(all_categorys),1)
self.assertEqual(all_categorys[0].model_name,model_model.table_name)
self.assertTrue(not all_categorys[0].has_key('models'))
示例3: test_delete
# 需要导入模块: from model import Model [as 别名]
# 或者: from model.Model import insert [as 别名]
def test_delete(self):
'''delete的同时要删除相关数据'''
category_model = self.model
model_model = Model()
new_category_id = category_model.insert(test_helper.storage({'title':'cat1'}))
new_model_id = model_model.insert(test_helper.storage({'Categoryid':new_category_id}))
inserted_model = getDBHelper().fetchOne('select * from '+model_model.table_name+' where '+model_model.primary_key+'=%s',new_model_id)
self.assertTrue(inserted_model is not None)
category_model.delete(new_category_id)
inserted_model = getDBHelper().fetchOne('select * from '+model_model.table_name+' where '+model_model.primary_key+'=%s',new_model_id)
self.assertTrue(inserted_model is None)