Commit 3374e0f4 authored by Brendan Fausto's avatar Brendan Fausto

defined authorview and bookview to fix error in Book-Edit and Author-Edit

parent 435723a9
from django.shortcuts import render from django.shortcuts import render, redirect
from django.views import View from django.views import View
from django.views.generic.detail import DetailView from django.views.generic.detail import DetailView
from django.views.generic.list import ListView from django.views.generic.list import ListView
from django.views.generic.edit import UpdateView from django.views.generic.edit import UpdateView
from django.shortcuts import get_object_or_404 from django.shortcuts import get_object_or_404
from django.views.generic.edit import CreateView, UpdateView from django.views.generic.edit import CreateView, UpdateView
from django.forms import formset_factory, BaseFormSet, HiddenInput, modelform_factory
from django.http import HttpResponse
from .models import Books, Authors from .models import Books, Authors
from .forms import BookForm, AuthorForm from .forms import BookForm, AuthorForm
...@@ -60,16 +62,31 @@ class AuthorCreateView(CreateView): ...@@ -60,16 +62,31 @@ class AuthorCreateView(CreateView):
class BookUpdateView(UpdateView): class BookUpdateView(UpdateView):
model = Books model = Books
form_class = BookForm fields = '__all__'
template_name = 'bookshelf/edit-book.html' template_name = 'bookshelf/edit-book.html'
def get_success_url(self):
return reverse_lazy('books_details', kwargs={'pk': self.object.pk})
class AuthorUpdateView(UpdateView): class AuthorUpdateView(UpdateView):
model = Authors model = Authors
form_class = AuthorEditForm fields = '__all__'
template_name = 'bookshelf/edit-author.html' template_name = 'bookshelf/edit-author.html'
def get_success_url(self):
return reverse_lazy('author_details', kwargs={'pk': self.object.pk})
def book_view(request):
book = Books.object.get(pk=self.object.pk)
if request.method == 'POST':
form = BookForm(request.POST, instance = book)
form.save()
BookModelFormFactory = modelform_factory(Books, fields='__all__')
form = BookModelFormFactory()
return render (request, 'bookshelf/edit-book.html' ,{'form':form})
def author_view(request):
author = Authors.object.get(pk=self.object.pk)
if request.method == 'POST':
form = AuthorForm(request.POST, instance = author)
form.save()
AuthorModelFormFactory = modelform_factory(Authors, fields='__all__')
form = AuthorModelFormFactory()
return render (request, 'bookshelf/edit-author.html', {'form':form})
# Create your views here. # Create your views here.
No preview for this file type
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