本文整理汇总了Python中models.Book.book_from_dict方法的典型用法代码示例。如果您正苦于以下问题:Python Book.book_from_dict方法的具体用法?Python Book.book_from_dict怎么用?Python Book.book_from_dict使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Book
的用法示例。
在下文中一共展示了Book.book_from_dict方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: bootstrapTestDB
# 需要导入模块: from models import Book [as 别名]
# 或者: from models.Book import book_from_dict [as 别名]
def bootstrapTestDB(db):
"""
Takes an created SQLAlchemy db and bootstraps the tables
with dummy data
"""
books_copy, authors_copy = deepcopy(books), deepcopy(authors)
# load authors
for author_data in authors:
db.session.add(Author.author_from_dict(**author_data))
db.session.commit()
# load genres
for book_data in books_copy:
for genre in book_data['genres']:
g = Genre.query.filter_by(name=genre).first()
if not g:
db.session.add(Genre(genre))
db.session.flush()
db.session.commit()
# load books
for book_data in books_copy:
book_data['genres'] = [ Genre.query.filter_by(name=genre_item).first()
for genre_item in book_data['genres'] ]
book_data['author'] = Author.query.filter_by(name=book_data['author']).first()
db.session.add(Book.book_from_dict(**book_data))
# commit the changes
db.session.commit()
#load users
for author_data in authors_copy:
author = Author.query.filter_by(name=author_data['name']).first()
db.session.add(AppUser(author_data['user_href'], author))
db.session.commit()