Commit b7610648 authored by justin's avatar justin

feat: new book form functionality complete, redirects done

parent 02285178
from django.shortcuts import render
from django.shortcuts import render, redirect
from django.urls import reverse
from django.views import View
from django.views.generic.list import ListView
from django.views.generic.detail import DetailView
......@@ -14,8 +15,16 @@ def index(request):
def add_book(request):
if request.method == 'POST':
form = BookForm(request.POST)
if form.is_valid():
book = form.save()
pk = book.pk
return redirect(reverse("book-detail", args=[pk]))
else:
form = BookForm()
return render(request, "bookshelf/add-book.html", {"form": form})
context = {"form": form}
return render(request, "bookshelf/add-book.html", context)
class BookListView(ListView):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment