Modified contents

parent 34ba7650
from django.shortcuts import render
from django.http import HttpResponse
from django.http import HttpResponse, Http404
from .models import Author, Book
from django.views import View
def index(request):
bookshelf_view = "Widget's Announcement Board <br/>"
author = Author.objects.all()
book = Book.objects.all()
return HttpResponse(bookshelf_view)
def home(request):
return render(request, "bookshelf/home.html")
class BooksView(View):
def get(self, request):
books_list= Book.objects.all().order_by("title")
return render(request, "bookshelf/books.html", {"books_list":books_list})
class BooksDetailView(View):
def get(self, request, book_id):
try:
book = Book.objects.get(pk=book_id)
except Book.DoesNotExist:
raise Http404("Book does not exist!")
return render(request, "bookshelf/book_detail.html", {"book":book})
class AuthorsView(View):
def get(self, request):
authors_list= Author.objects.all().order_by("first_name")
return render(request, "bookshelf/authors.html", {"authors_list":authors_list})
class AuthorsDetailView(View):
def get(self, request, author_id):
try:
author = Author.objects.get(pk=author_id)
except Author.DoesNotExist:
raise Http404("Author does not exist!")
books_list= Book.objects.all().filter(author=author)
return render(request, "bookshelf/author_detail.html", {"author":author,"books_list":books_list})
\ 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