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