Imported the new ModelForms and created class-based views to create or update data

parent b078b076
...@@ -2,8 +2,10 @@ from django.shortcuts import render ...@@ -2,8 +2,10 @@ from django.shortcuts import render
from django.views import View from django.views import View
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, UpdateView
from .models import Author, Books from .models import Author, Books
from .forms import AuthorForm, BooksForm
class HomepageView(View): class HomepageView(View):
...@@ -31,3 +33,27 @@ class AuthorsPageView(ListView): ...@@ -31,3 +33,27 @@ class AuthorsPageView(ListView):
class AuthorsDetailsView(DetailView): class AuthorsDetailsView(DetailView):
model = Author model = Author
template_name = 'bookshelf/author_details.html' template_name = 'bookshelf/author_details.html'
class AddBookView(CreateView):
model = Books
form_class = BooksForm
template_name = 'bookshelf/add-book.html'
class EditBookView(UpdateView):
model = Books
form_class = BooksForm
template_name = 'bookshelf/add-book.html'
class AddAuthorView(CreateView):
model = Author
form_class = AuthorForm
template_name = 'bookshelf/add-author.html'
class EditAuthorView(UpdateView):
model = Author
form_class = AuthorForm
template_name = 'bookshelf/add-author.html'
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