本文整理汇总了Python中books.models.Book.series方法的典型用法代码示例。如果您正苦于以下问题:Python Book.series方法的具体用法?Python Book.series怎么用?Python Book.series使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类books.models.Book
的用法示例。
在下文中一共展示了Book.series方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: bibtex
# 需要导入模块: from books.models import Book [as 别名]
# 或者: from books.models.Book import series [as 别名]
def bibtex(request):
if request.method == "POST":
if "_parse" in request.POST:
form = ParseBibTexForm(request.POST)
if form.is_valid():
entries = parsers.bibtex(form.cleaned_data["bibtex"])
if len(entries) >= 1:
messages.add_message(request, messages.SUCCESS, "Successfully parsed entry from BibTex.")
e = entries[0]
form = ParsedBibTexForm(
initial={
"title": e["title"],
"authors": "\n".join(str(author) for author in e["authors"]),
"series": e["journal"],
"volume": e["volume"],
"publisher": e["publisher"],
"published_on": e["published_on"],
"url": e["url"],
"bibtex": e["bibtex"],
}
)
return render(request, "books/admin/parsed_bibtex.html", locals())
else:
messages.add_message(request, messages.ERROR, "No entries found.")
return render(request, "books/admin/parse_bibtex.html", locals())
else:
return render(request, "books/admin/parse_bibtex.html", locals())
elif "_create_book" in request.POST:
form = ParsedBibTexForm(request.POST)
if form.is_valid():
series, created = (
Series.objects.get_or_create(name=form.cleaned_data["series"])
if form.cleaned_data["series"]
else (None, False)
)
publisher, created = (
Publisher.objects.get_or_create(name=form.cleaned_data["publisher"])
if form.cleaned_data["publisher"]
else (None, False)
)
book = Book()
book.title = form.cleaned_data["title"]
book.published_on = form.cleaned_data["published_on"]
book.series = series
book.volume = form.cleaned_data["volume"]
book.publisher = publisher
book.bibtex = form.cleaned_data["bibtex"]
book.save()
authors = form.cleaned_data["authors"].split("\n")
for author in authors:
author = eval(author)
person, created = Person.objects.get_or_create(
firstname=author["firstname"], lastname=author["lastname"]
)
book.authors.add(person)
book.save()
if form.cleaned_data["url"]:
Url.objects.create(url=form.cleaned_data["url"], book=book)
messages.add_message(request, messages.SUCCESS, "Successfully created Book from BibTex.")
return redirect("admin:books_book_change", book.id)
else:
messages.add_message(request, messages.ERROR, "Can not create book.")
return render(request, "books/admin/parsed_bibtex.html", locals())
else:
form = ParseBibTexForm()
return render(request, "books/admin/parse_bibtex.html", locals())