Created edit and add pages for books and authors

parent ef3ab0fc
from django.urls import path
from .views import home, AuthorsView, AuthorDetailsView, BooksView, BookDetailsView
from .views import (
home, AuthorsView, AuthorDetailsView, BooksView, BookDetailsView,
AuthorsCreateView, AuthorsUpdateView, BooksCreateView, BooksUpdateView
)
urlpatterns = [
path('home/', home, name='home'),
path('authors/', AuthorsView.as_view(), name='author-list'),
path('author/<int:pk>/details/', AuthorDetailsView.as_view(), name='author-details'),
path('books/add/',BooksCreateView.as_view(),name='add-book'),
path('books/<int:pk>/edit/',BooksUpdateView.as_view(),name='update-book'),
path('books/', BooksView.as_view(), name='book-list'),
path('book/<int:pk>/details/', BookDetailsView.as_view(), name='book-details'),
path('authors/add/',AuthorsCreateView.as_view(),name='add-author'),
path('authors/<int:pk>/edit/',AuthorsUpdateView.as_view(),name='update-author'),
]
app_name = "bookshelf"
\ No newline at end of file
from django.shortcuts import render
from django.views.generic.detail import DetailView
from django.views.generic.list import ListView
from django.views.generic.edit import CreateView, UpdateView
from .models import Author, Book
def home(request):
......@@ -11,17 +11,36 @@ class AuthorsView(ListView):
model = Author
template_name = 'bookshelf/authors.html'
class BooksView(ListView):
model = Book
template_name = 'bookshelf/books.html'
class AuthorDetailsView(DetailView):
model = Author
template_name = 'bookshelf/author_details.html'
class BookDetailsView(DetailView):
model = Book
template_name = 'bookshelf/book_details.html'
class AuthorsCreateView(CreateView):
model = Author
fields = '__all__'
template_name = "bookshelf/add-author.html"
class BooksCreateView(CreateView):
model = Book
fields = '__all__'
template_name = "bookshelf/add-book.html"
class AuthorsUpdateView(UpdateView):
model = Author
fields = '__all__'
template_name = "bookshelf/edit-author.html"
class BooksUpdateView(UpdateView):
model = Book
fields = '__all__'
template_name = "bookshelf/edit-book.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