本文整理汇总了Python中models.Author.books方法的典型用法代码示例。如果您正苦于以下问题:Python Author.books方法的具体用法?Python Author.books怎么用?Python Author.books使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Author
的用法示例。
在下文中一共展示了Author.books方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: edit_author
# 需要导入模块: from models import Author [as 别名]
# 或者: from models.Author import books [as 别名]
def edit_author(id):
'''Editing or adding author depending on given id.'''
if id == 'new':
author = Author()
else:
author = Author.query.filter_by(id=id).first_or_404()
form = AuthorForm(request.form, obj=author)
if request.method == 'GET':
return render_template('edit_author.html', form=form)
if request.method == 'POST' and form.validate():
form.populate_obj(author)
author.name = form.name.data
author.books = form.books.data
if id == 'new':
db.session.add(author)
flash('Author was successfully added')
else:
db.session.merge(author)
flash('Author info was successfully updated')
db.session.commit()
return redirect(url_for('author', id=author.id))
else:
return render_template('edit_author.html', form=form)