Beispiel #1
0
def updata_book(request):
    book = Book.objects.get(ISBN = request.GET['ISBN'])
    author_list = Author.objects.all()
    if request.POST:
        book.delete()
        post = request.POST
        new_book = Book(
        ISBN = post["ISBN"],
        Title = post["Title"],
        AuthorID = Author.objects.get(AuthorID=post["AuthorID"]),
        Publisher = post["Publisher"],
        PublishDate = post["PublishDate"],
        Price = post["Price"],)
        new_book.save()
        return render_to_response("updatas.html")
    return render_to_response("updata.html",Context({"Book":book,"author_list":author_list,}))
Beispiel #2
0
def add_book(request):
    global ids
    if request.POST:
        post = request.POST
        try: 
            Book.objects.get(ISBN = post["ISBN"])
            return HttpResponse("此图书已经存在!")
        except:
            new_book = Book(
            ISBN = post["ISBN"],
            Title = post["Title"],
            AuthorID = Author.objects.get(AuthorID=post["AuthorID"]),
            Publisher = post["Publisher"],
            PublishDate = post["PublishDate"],
            Price = post["Price"],)
            new_book.save()
    book_list=Book.objects.all()
    author_list=Author.objects.all()
    return render_to_response('add.html',Context({"book_list":book_list,"author_list":author_list,}))