本文整理汇总了Python中models.Book.year方法的典型用法代码示例。如果您正苦于以下问题:Python Book.year方法的具体用法?Python Book.year怎么用?Python Book.year使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Book
的用法示例。
在下文中一共展示了Book.year方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: insert_data
# 需要导入模块: from models import Book [as 别名]
# 或者: from models.Book import year [as 别名]
def insert_data(self, data):
"""
Will handle inserting data into the database
"""
try:
# Check if book is in database, if so update else create
try:
book = db_session.query(Book).filter(Book.book_id == data.get('book_id')).one()
except NoResultFound:
book = Book()
book.title = data.get('title')
book.subtitle = data.get('subtitle')
book.author = data.get('author')
book.year = data.get('year')
book.pages = data.get('pages')
book.language = data.get('language')
book.publisher = data.get('publisher')
book.isbn = data.get('isbn')
book.format = data.get('format')
book.description = data.get('description')
book.file_source = data.get('file_source')
book.file_cover_source = data.get('file_cover_source')
book.file_location = data.get('file_location')
book.file_cover_location = data.get('file_cover_location')
book.book_id = data.get('book_id')
book.time_collected = data.get('time_collected')
db_session.add(book)
db_session.commit()
# self.track_stat('rows_added_to_db', rows_affected)
except Exception:
db_session.rollback()
logger.exception("Error adding to db {data}".format(data=data))
示例2: add
# 需要导入模块: from models import Book [as 别名]
# 或者: from models.Book import year [as 别名]
def add(request):
if request.method == "POST":
form = BookAddForm(request.POST)
if form.is_valid():
book = Book()
book.title = form.cleaned_data['title']
book.author = form.cleaned_data['author']
book.press = form.cleaned_data['press']
book.year = form.cleaned_data['year']
book.save()
messages.success(request, "已保存")
form = BookAddForm()
else:
messages.error(request, "保存失败,请检查所填写的内容!")
else:
form = BookAddForm()
context = RequestContext(request, {
"form":form,
})
return render_to_response("add.html", context)