示例#1
0
def delete_book(id):
    error = None
    book = Book.query.get(id)
    if not book:
        error = 'Sorry, we don\'t have the book with id {0}.'.format(id)
    if request.method == 'POST':
        db_session.delete(book)
        db_session.commit()
        flash('The book was deleted.')
        return redirect(url_for('view_book'))
    return render_template('library/delete_book.html', book=book, error=error)
示例#2
0
def delete_author(id):
    error = None
    author = Author.query.get(id)
    if not author:
        error = 'Sorry, we don\'t have the author with id {0}.'.format(id)
    if request.method == 'POST':
        db_session.delete(author)
        db_session.commit()
        flash('The author and his books were deleted.')
        return redirect(url_for('view_author'))
    return render_template('library/delete_author.html', author=author,
                           error=error)