Complete html

parent 53fd3492
{% extends 'base.html' %}
{% load static %}
{% block title %}{{author.first_name}} {{author.last_name}}{% endblock %}
{% block content %}
<h1>{{author.first_name}} {{author.last_name}}</h1>
<p>
{{author.age}} <br />
{{author.nationality}} <br />
{{author.bio}} <br />
Books by {{author.first_name}} {{author.last_name}} I love:
<ol>
{% for object in books %}
<li><a href = "../../../books/{{object.pk}}/details/">{{ object.title }}</a></li>
{% empty %}
<li>No books registered.</li>
{% endfor %}
</ol>
<br />
<br />
<br />
<a href = "../../../home/">Home</a>
<a href = "../../../books/">Books</a>
<a href = "../../../authors/">Authors</a>
</p>
{% endblock %}
\ No newline at end of file
......@@ -7,9 +7,17 @@
<h1>Gareth's Favorite Authors:</h1>
<ol>
{% for object in object_list %}
<li><a href = "authors/{{ object.id }}/details/">{{ object.first_name }}, {{ object.last_name }}</a></li>
<li><a href = "{{ object.id }}/details/">{{ object.first_name }} {{ object.last_name }}</a></li>
{% empty %}
<li>No books registered.</li>
{% endfor %}
</ol>
<p>
<br />
<br />
<br />
<a href = "../home/">Home</a>
<a href = "../books/">Books</a>
</p>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block title %}{{book.title}}{% endblock %}
{% block content %}
<h1>{{book.title}}</h1>
<p>
<a href = "../../../authors/{{book.author.pk}}/details/">{{book.author.first_name}} {{book.author.last_name}}</a> <br />
{{book.publisher}} <br />
{{book.year_published}} <br />
{{book.isbn}} <br />
{{book.blurb}} <br />
<br />
<br />
<br />
<a href = "../../../home/">Home</a>
<a href = "../../../books/">Books</a>
<a href = "../../../authors/">Authors</a>
</p>
{% endblock %}
\ No newline at end of file
......@@ -7,9 +7,17 @@
<h1>Gareth's Favorite Books:</h1>
<ol>
{% for object in object_list %}
<li><a href = "books/{{ object.id }}/details/">{{ object.title }}</a></li>
<li><a href = "{{ object.id }}/details/">{{ object.title }}</a></li>
{% empty %}
<li>No books registered.</li>
{% endfor %}
</ol>
<p>
<br />
<br />
<br />
<a href = "../home/">Home</a>
<a href = "../authors/">Authors</a>
</p>
{% endblock %}
\ No newline at end of file
......@@ -5,5 +5,11 @@
{% block content %}
<h1>Welcome to Gareth's Database of Favorite Books and Authors!</h1>
<p>I enjoy a variety of genres, no specific one, as long as it is good.</p>
<p>I enjoy a variety of genres, no specific one, as long as it is good.
<br />
<br />
<br />
<a href = "../books/">Books</a>
<a href = "../authors/">Authors</a>
</p>
{% endblock %}
\ No newline at end of file
......@@ -5,8 +5,8 @@ urlpatterns = [
path('home/', views.homepage_view, name='home'),
path('books/', views.book_view.as_view(), name='books'),
path('authors/', views.author_view.as_view(), name='authors'),
#path('book_details/', views.homepage_view, name='home'),
#path('author_details/', views.homepage_view, name='home'),
path('books/<int:book_id>/details/', views.bookdetails_view.as_view(), name='book_details'),
path('authors/<int:author_id>/details/', views.authordetails_view.as_view(), name='author_details'),
]
app_name = "bookshelf"
\ No newline at end of file
from django.http import HttpResponse
from django.http import HttpResponse, Http404
from django.shortcuts import render
from django.views import View
from .models import Author, Books
......@@ -15,3 +15,26 @@ class author_view(View):
def get(self, request):
name = Author.objects.order_by("first_name")
return render(request, 'bookshelf/authors.html', {'object_list': name})
class bookdetails_view(View):
def get(self, request, book_id):
try:
book = Books.objects.get(pk = book_id)
except Books.DoesNotExist:
raise Http404("Book Does Not Exist")
displaybook = Books.objects.get(pk = book_id)
return render(request, 'bookshelf/book_details.html', {'book': displaybook})
class authordetails_view(View):
def get(self, request, author_id):
try:
author = Author.objects.get(pk = author_id)
except Author.DoesNotExist:
raise Http404("Author Does Not Exist")
displayauthor = Author.objects.get(pk = author_id)
books = Books.objects.filter(author = displayauthor)
context = {
"author": displayauthor,
"books": books
}
return render(request, 'bookshelf/author_details.html', context)
\ 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