def edit_book_view(request, book_id): book_list = Book.objects.get(id=book_id) book_form = BookForm(instance=book_list) if request.POST: book_form = BookForm(request.POST, instance=book_list) if book_form.is_valid(): book_form.save() return redirect("create_book") return render_to_response("edit_book.html", RequestContext(request, { "book_list": book_list, "book_form": book_form, }))
def create_book_view(request): book_list = Book.objects.all() book_form = BookForm() if request.POST: book_form = BookForm(request.POST) if book_form.is_valid(): book_form.save() return redirect("create_book") return render_to_response("create_book.html", RequestContext(request, { "book_list": book_list, "book_form": book_form, }))
def edit_book_view(request, book_id): book_list = Book.objects.get(id=book_id) book_form = BookForm(instance=book_list) if request.POST: book_form = BookForm(request.POST, instance=book_list) if book_form.is_valid(): book_form.save() return redirect("create_book") return render_to_response( "edit_book.html", RequestContext(request, { "book_list": book_list, "book_form": book_form, }))
def create_book_view(request): book_list = Book.objects.all() book_form = BookForm() if request.POST: book_form = BookForm(request.POST) if book_form.is_valid(): book_form.save() return redirect("create_book") return render_to_response( "create_book.html", RequestContext(request, { "book_list": book_list, "book_form": book_form, }))