当前位置: 首页>>代码示例>>Python>>正文


Python Book.add方法代码示例

本文整理汇总了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)
开发者ID:yaroslav-dudar,项目名称:prom-ua-test-task,代码行数:34,代码来源:views.py

示例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
开发者ID:elshobaky,项目名称:MeX-LMS,代码行数:23,代码来源:excel_import.py


注:本文中的models.Book.add方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。