Commit 37405267 authored by Ysabella Panghulan's avatar Ysabella Panghulan

edited AuthorCreateView

parent 6dd26e0b
from django.http import HttpResponse from django.http import HttpResponse
from .models import Author, Books from .models import Author, Books
from django.views import View from django.views import View
from django.shortcuts import render from django.shortcuts import render, redirect
from django.views.generic.list import ListView from django.views.generic.list import ListView
from django.views.generic.detail import DetailView from django.views.generic.detail import DetailView
from django.views.generic.edit import CreateView from django.views.generic.edit import CreateView
...@@ -34,4 +34,13 @@ class AuthorDetailView(DetailView): ...@@ -34,4 +34,13 @@ class AuthorDetailView(DetailView):
class AuthorCreateView(CreateView): class AuthorCreateView(CreateView):
model = Author model = Author
template_name = 'bookshelf/add-author.html'
fields = '__all__' fields = '__all__'
def post(self, request, *args, **kwargs):
form = self.get_form()
if form.is_valid():
author = form.save()
return redirect('author-details', pk=author.pk)
else:
return self.form_invalid(form)
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