Commit 79e44495 authored by KaoruSawade's avatar KaoruSawade

Updated views.py and urls.py to implement books page and per book page via CBV

parent 6d916cf2
from django.urls import path
from .views import home, AuthorListView, AuthorDetailView
from .views import home, AuthorListView, AuthorDetailView, BooksListView, BooksDetailView
urlpatterns = [
path('home/', home, name='home'),
path('authors/', AuthorListView.as_view(), name='author-list'),
path('authors/<int:pk>/details', AuthorDetailView.as_view(), name='author-detail'),
path('books/', BooksListView.as_view(), name='books-list'),
path('books/<int:pk>/details', BooksDetailView.as_view(), name='books-detail'),
]
app_name = "bookshelf"
......@@ -16,5 +16,15 @@ class AuthorDetailView(DetailView):
def get(self, request, pk):
author = Author.objects.get(pk=pk)
book_list = Books.objects.filter(author__first_name__exact=author.first_name)
return render(request, 'bookshelf/author_detail.html', {'author': author, 'book_list': book_list})
class BooksListView(ListView):
def get(self, request):
books_list = Books.objects.all()
return render(request, 'bookshelf/books_list.html', {'name': 'Carlos', 'books_list': books_list})
class BooksDetailView(DetailView):
def get(self, request, pk):
book = Books.objects.get(pk=pk)
author = book.author
return render(request, 'bookshelf/books_detail.html', {'author': author, 'book': book})
\ No newline at end of file
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