Implemented every view in the specs with working links and the correct layout

parent 2fdd6b7f
{% extends 'base.html' %}
{% load static %}
{% block title %}{{ author }}{% endblock %}
{% block content %}
<h1>{{ author }}<br></h1>
<p>{{ author.age }}<br></p>
<p>{{ author.nationality }}<br></p>
<p>{{ author.bio }}<br></p>
<p>Books by {{ author }} I love:<br></p>
<ul style="list-style-type:circle"></ul>
{% for book in booklist %}
<li><a href="{{ book.get_absolute_url }}">{{ book }}</a></li>
{% endfor %}
<br></ul>
<a href="http://localhost:8000/home/">Home</a>
<a href="http://localhost:8000/books/">Books</a>
<a href="http://localhost:8000/authors/">Authors</a>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block title %}My Favorite Authors{% endblock %}
{% block content %}
<h1>Matt's Favorite Authors:<br><br></h1>
<ul style="list-style-type:circle">
{% for author in authors %}
<li><a href="{{ author.get_absolute_url }}">{{ author.first_name }}&nbsp;{{ author.last_name }}</a></li>
{% endfor %}
</ul>
<a href="http://localhost:8000/home/">Home</a>
<a href="http://localhost:8000/books/">Books</a>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block title %}My Favorite Books{% endblock %}
{% block title %}{{ book.title }}{% endblock %}
{% block content %}
<h1>Matt's Favorite Books:<br><br></h1>
<ul style="list-style-type:circle">
{% for book in books %}
<li><a href="{{ book.get_absolute_url }}">{{ book.title }}</a></li>
{% endfor %}
</ul>
<h1>{{ book.title }}<br><br></h1>
<p><a href="{{ book.author.get_absolute_url }}">{{ book.author }}</a><br></p>
<p>{{ book.publisher }}<br></p>
<p>{{ book.year_published }}<br></p>
<p>{{ book.ISBN }}<br></p>
<p>{{ book.blurb }}<br><br></p>
<a href="http://localhost:8000/home/">Home</a>
<a href="http://localhost:8000/books/">Books</a>
<a href="http://localhost:8000/authors/">Authors</a>
{% endblock %}
\ No newline at end of file
from django.urls import path
from .views import homepage, BooksView, BookDetailView
from .views import homepage, BooksView, BookDetailView, AuthorsView, AuthorDetailView
urlpatterns = [
path('home/', homepage, name='homepage'),
path('books/', BooksView.as_view(), name='book-list'),
path('books/<int:pk>/details', BookDetailView.as_view(), name='book-detail')
path('books/<int:pk>/details', BookDetailView.as_view(), name='book-detail'),
path('authors/', AuthorsView.as_view(), name='author-list'),
path('authors/<int:pk>/details', AuthorDetailView.as_view(), name='author-detail'),
]
app_name = "bookshelf"
\ No newline at end of file
......@@ -12,9 +12,9 @@ class BooksView(ListView):
return render(request, 'bookshelf/books.html', {'books': books})
class BookDetailView(DetailView):
def get(self, request):
books = Book.objects.all()
return render(request, 'bookshelf/book_details.html', {'books': books})
def get(self, request, pk):
specificbook = Book.objects.get(pk=pk)
return render(request, 'bookshelf/book_details.html', {'book': specificbook})
class AuthorsView(ListView):
def get(self, request):
......@@ -22,6 +22,7 @@ class AuthorsView(ListView):
return render(request, 'bookshelf/authors.html', {'authors': authors})
class AuthorDetailView(DetailView):
def get(self, request):
authors = Author.objects.all()
return render(request, 'bookshelf/author_details.html', {'authors': authors})
\ No newline at end of file
def get(self, request, pk):
specificauthor = Author.objects.get(pk=pk)
authorbooklist = Book.objects.filter(author__exact=specificauthor)
return render(request, 'bookshelf/author_details.html', {'author': specificauthor, 'booklist': authorbooklist})
\ 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