本文整理汇总了Python中books.models.Book.name方法的典型用法代码示例。如果您正苦于以下问题:Python Book.name方法的具体用法?Python Book.name怎么用?Python Book.name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类books.models.Book
的用法示例。
在下文中一共展示了Book.name方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: addBook
# 需要导入模块: from books.models import Book [as 别名]
# 或者: from books.models.Book import name [as 别名]
def addBook(request,userId):
user = User.objects.get(pk=userId)
book = Book(originOwner=user,currentOwner=user)
book.name = request.POST['name']
book.author = request.POST['author']
book.kind = request.POST['kind']
book.description = request.POST['description']
book.picture = request.FILES['picture']
book.save()
return HttpResponse(200)
示例2: addBook
# 需要导入模块: from books.models import Book [as 别名]
# 或者: from books.models.Book import name [as 别名]
def addBook(request):
'''新加书籍, post request only'''
if request.method != "POST":
raise Http404
authorName = request.REQUEST.get('authorName', None)
authorDesc = request.REQUEST.get('authorDesc', None)
bookName = request.REQUEST.get('bookName', None)
bookPrice = request.REQUEST.get('bookPrice', None)
bookIsbn = request.REQUEST.get('bookIsbn', None)
bookPress = request.REQUEST.get('bookPress', None)
bookDesc = request.REQUEST.get('bookDesc', None)
bookBinding = request.REQUEST.get('bookBinding', None)
bookPages = request.REQUEST.get('bookPages', None)
bookSpic = request.REQUEST.get('bookSpic', None)
bookMpic = request.REQUEST.get('bookMpic', None)
bookLpic = request.REQUEST.get('bookLpic', None)
bookPublishDate = request.REQUEST.get('bookPublishDate', None)
stock = request.REQUEST.get('stock', None)
category = request.REQUEST.get('category', None)
author = Author(name=authorName, desc=authorDesc)
author.save()
price = float(''.join([ item for item in bookPrice if item in '1234567890.' ]))
try:
cate = Category.objects.get(label=category)
except Category.DoesNotExist:
raise Http404
try:
book = Book.objects.get(isbn=bookIsbn)
except Book.DoesNotExist:
book = Book()
book.name=bookName
book.author=author
book.price=price
book.isbn=bookIsbn
book.press=bookPress
book.desc=bookDesc
book.binding=bookBinding
book.pages=bookPages
book.spic=bookSpic
book.mpic=bookMpic
book.lpic=bookLpic
book.publish_date=bookPublishDate
book.stock=stock
book.category=cate
book.save()
utils.addMsg(request, messages.SUCCESS, '添加成功!')
return HttpResponseRedirect('/manage/reg_book/')
示例3: regFromDouban
# 需要导入模块: from books.models import Book [as 别名]
# 或者: from books.models.Book import name [as 别名]
def regFromDouban(request):
'''利用豆瓣API获取书籍信息加入数据库'''
try:
DOUBAN = "https://api.douban.com/v2/book/search?q="
q = request.REQUEST.get('q', '')
q = urllib.quote(q.decode('utf8').encode('utf8'))
DOUBAN += q
req = urllib.urlopen(DOUBAN)
resp = req.read()
result = simplejson.loads(resp)
books = result['books']
for i in range(len(books)):
author = Author()
author.name = books[i]['author'][0]
author.desc = books[i]['author_intro']
author.save()
try:
book = Book.objects.get(isbn=books[i]['isbn13'])
except Book.DoesNotExist:
book = Book()
book.name = books[i]['title']
book.author = author
book.price = float(''.join([ item for item in books[i]['price'] if item in '1234567890.' ]))
if not books[i]['isbn13']:
book.isbn = books[i]['isbn10']
else:
book.isbn = books[i]['isbn13']
book.press = books[i]['publisher']
book.desc = books[i]['summary']
book.binding = books[i]['binding']
book.pages = books[i]['pages']
book.spic = _downloadImg(books[i]['images']['small'], 'small')
book.mpic = _downloadImg(books[i]['images']['medium'], 'medium')
book.lpic = _downloadImg(books[i]['images']['large'], 'large')
book.stock = 140
book.publish_date = books[i]['pubdate']
book.category = _getBookCate('letter')
book.save()
return HttpResponse('success')
except Exception:
return HttpResponse('error')
示例4: add
# 需要导入模块: from books.models import Book [as 别名]
# 或者: from books.models.Book import name [as 别名]
def add(request):
if request.method == 'GET':
form = BookAddForm()
else:
form = BookAddForm(request.POST)
if form.is_valid():
id_of_author=form.cleaned_data['author_id']
name_of_the_book = form.cleaned_data['name']
author_object = Author.objects.get(id=id_of_author)
book_object = Book()
book_object.name = name_of_the_book
book_object.author_name = author_object
book_object.save()
return HttpResponseRedirect('/landingpage/')
print author_object.name
return render(request, 'books/addbook.html', {'addbookform':form})