本文整理汇总了Python中models.Book.add方法的典型用法代码示例。如果您正苦于以下问题:Python Book.add方法的具体用法?Python Book.add怎么用?Python Book.add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Book
的用法示例。
在下文中一共展示了Book.add方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: books
# 需要导入模块: from models import Book [as 别名]
# 或者: from models.Book import add [as 别名]
def books():
book_edit_form_errors = None
book_edit_forms = []
# generate book edit forms
for book in Book.query.all():
book_edit_form = BookEditForm()
writers = Writer.query.all()
book_edit_form.writers.data = [writer.id for writer in book.writers]
book_edit_form.title.data = book.title
book_edit_form.id.data = book.id
book_edit_forms.append(book_edit_form)
if request.method == 'GET':
book_add_form = BookAddForm()
else:
if request.form['btn'] == 'Edit':
book_add_form = BookAddForm()
book_edit_form_errors = BookEditForm(request.form)
if book_edit_form_errors.validate():
writers = Writer.query.filter(Writer.id.in_(book_edit_form_errors.writers.data)).all()
book = Book.query.filter(Book.id == book_edit_form_errors.id.data).first()
book.edit(title=book_edit_form_errors.title.data, writers=writers)
return redirect(url_for('books'))
else:
book_add_form = BookAddForm(request.form)
if book_add_form.validate():
writer_ids = [writer.id for writer in book_add_form.writers.data]
writers = Writer.query.filter(Writer.id.in_(writer_ids)).all()
Book.add(title=book_add_form.title.data, writers=writers)
return redirect(url_for('books'))
return render_template('books.html', book_add_form=book_add_form,
book_edit_forms=book_edit_forms, book_edit_form_errors=book_edit_form_errors)
示例2: add_books_to_db
# 需要导入模块: from models import Book [as 别名]
# 或者: from models.Book import add [as 别名]
def add_books_to_db(fin=books_json):
from PyQt4 import QtCore
from models import Book, Cat
with open(fin, 'r') as books_file:
data = books_file.read()
data = json.loads(data)
cats = data.keys()
for c in cats:
cat = Cat(name=c)
cat.put()
cat = Cat.get(name=c)[0]
cat_id = cat.id
for book in data[c]:
title = book[0]
cat_order = book[1]
if cat_order.isdigit():
b = Book.add(title=title, cat_id=cat_id,
cat_order=int(cat_order), copies=1,
available=True)
if type(b) in [str, QtCore.QString]:
print b, title, cat_order