本文整理汇总了Python中models.Author.exists方法的典型用法代码示例。如果您正苦于以下问题:Python Author.exists方法的具体用法?Python Author.exists怎么用?Python Author.exists使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Author
的用法示例。
在下文中一共展示了Author.exists方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: edit_book
# 需要导入模块: from models import Author [as 别名]
# 或者: from models.Author import exists [as 别名]
def edit_book(id):
book = Book.query.get(id)
if book == None:
flash("Book is not found")
return redirect(url_for('books'))
print book.authors
form = EditBook(book=book)
print form.data, 'hah'
#form.authors.min_entries = len(book.authors)
# print form.authors.data
# form.authors[0].data = book.authors[0].name
# for author in book.authors[1:]:
# form.authors.append_entry(author.name)
# print form.authors.data
if form.validate_on_submit():
print form.data
name = form.data['title']
newbook = Book.query.filter_by(name=name).first()
if newbook and id != newbook.id:
flash("Can't change name to existing one.")
return redirect(url_for('edit_book', id=id))
book.name = name
authors = list(set([Author.by_name(name=a)
for a in form.data['authors'] if Author.exists(name=a)]))
#print authors
book.authors = authors
db.session.commit()
flash('Changes have been saved.')
return redirect(url_for('edit_book', id=id))
return render_template('edit_book.html', form=form)
示例2: add_book
# 需要导入模块: from models import Author [as 别名]
# 或者: from models.Author import exists [as 别名]
def add_book():
form = AddBook()
if form.validate_on_submit():
title = form.data['title']
book = Book.query.filter_by(name=title).first()
if book:
flash('Book already exists.')
return redirect(url_for('edit_book', id=book.id))
authors = list(set([Author.by_name(name=a)
for a in form.data['authors'] if Author.exists(name=a)]))
book = Book(title, authors)
db.session.add(book)
db.session.commit()
flash('Book has been added.')
return redirect(url_for('books'))
print form.data['authors']
return render_template('add_book.html', form=form)