Created edit and add pages for books and authors

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