Commit 19ff60ac authored by Washington99's avatar Washington99

Finished Add Author functionality

The form now saves the new entry into the database. It also redirects to the details page of the new entry.
parent a7eaad9e
...@@ -34,6 +34,16 @@ class AuthorCreateView(CreateView): ...@@ -34,6 +34,16 @@ class AuthorCreateView(CreateView):
fields = '__all__' fields = '__all__'
template_name = 'bookshelf/add-author.html' template_name = 'bookshelf/add-author.html'
def post(self, request, *args, **kwargs):
form = AuthorForm(request.POST) # Create a Form object from the POST values
if form.is_valid():
new_author = form.save()
redirect_link = "../" + new_author.get_absolute_url() + "/details/"
return HttpResponseRedirect(redirect_link)
# return self.get(request, *args, **kwargs)
else:
return render(request, self.template_name, {'form': form})
class BooksCreateView(CreateView): class BooksCreateView(CreateView):
model = Books model = Books
form = BookForm # Can be removed? form = BookForm # Can be removed?
......
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