Commit b7610648 authored by justin's avatar justin

feat: new book form functionality complete, redirects done

parent 02285178
......@@ -11,7 +11,7 @@
</ul>
{% endif %}
{% endfor %}
<form action="/books/add" method="post">
<form action="/books/add" method="post">
{% csrf_token %}
{{form}}
<input type="submit" value="Submit" />
......
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):
form = BookForm()
return render(request, "bookshelf/add-book.html", {"form": form})
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()
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