def add(request): book_list = Book() if request.POST: book_list.ISBN = request.POST['ISBN'] book_list.Title = request.POST['Title'] book_list.AuthorID = request.POST['AuthorID'] book_list.Publisher = request.POST['Publisher'] book_list.PublishDate = request.POST['PublishDate'] book_list.Price = request.POST['Price'] author_id = book_list.AuthorID book_list.save() try: author = Author.objects.get(AuthorID = author_id) return render_to_response('add_Successed.html') except: return render(request,'needauthor.html') else: return render(request,'add.html')
def addbook(request): if request.POST: name = request.POST['name'] try: author = Author.objects.get(Name=name) except: return render_to_response('addau.html',) else: book = Book() book.AuthorID = author book.Publisher = request.POST['publisher'] book.Title = request.POST['title'] book.PublishDate = request.POST['publishdate'] book.Price = request.POST['price'] book.save() books = Book.objects.all() authors = Author.objects.all() return render_to_response('home.html',locals()) else: return render_to_response('addbook.html',)