本文整理汇总了Python中models.Item.to_dict方法的典型用法代码示例。如果您正苦于以下问题:Python Item.to_dict方法的具体用法?Python Item.to_dict怎么用?Python Item.to_dict使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Item
的用法示例。
在下文中一共展示了Item.to_dict方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: init_test_data
# 需要导入模块: from models import Item [as 别名]
# 或者: from models.Item import to_dict [as 别名]
def init_test_data():
# add item1
item1 = Item("mario", 1000, "a happy mario toy", "1.png", 12, 1, 10)
dict1 = item1.to_dict()
redis_manager.set_dict(dict1, 12, 1)
# add item2
item2 = Item("doraamon", 1500, "a cute doraamon", "2.png", 12, 2, 15)
dict2 = item2.to_dict()
redis_manager.set_dict(dict2, 12, 2)
示例2: get_books
# 需要导入模块: from models import Item [as 别名]
# 或者: from models.Item import to_dict [as 别名]
def get_books(self, *args, **kwargs):
_ts = time.time()
books = self.db.get_data_as_dict(*args, **kwargs)
logging.debug("[%5d ms] select books from library (count = %d)"
% ( int(1000*(time.time() - _ts)), len(books) ) )
item = Item()
empty_item = item.to_dict()
empty_item['collector'] = self.session.query(Reader).order_by(Reader.id).first()
ids = [ book['id'] for book in books ]
items = self.session.query(Item).filter(Item.book_id.in_(ids)).all()
maps = {}
for b in items:
d = b.to_dict()
c = b.collector.to_dict() if b.collector else empty_item['collector']
d['collector'] = c
maps[b.book_id] = d
for book in books:
book.update( maps.get(book['id'], empty_item) )
logging.debug("[%5d ms] select books from database (count = %d)"
% ( int(1000*(time.time() - _ts)), len(books) ) )
return books