Commit 5ee8933e authored by justin's avatar justin

Created detail HTML pages for each book

parent 4b2ebb81
from django.db import models
from django.urls import reverse
from django.core.exceptions import ValidationError
......@@ -31,3 +32,9 @@ class Books(models.Model):
def __str__(self):
return self.title
def get_absolute_url(self):
return reverse(
"book-detail",
kwargs={"pk": self.pk},
)
{% extends 'base.html' %}
{% block title %} {{ object.title }} {% endblock %}
{% block content %}
<div class="book-details">
<h1>{{ object.title }}</h1>
<ul>
<li>{{ object.author }}</li>
<li>{{ object.publisher }}</li>
<li>{{ object.year_published }}</li>
<li>{{ object.isbn }}</li>
<li>{{ object.blurb }}</li>
</ul>
</div>
<ul>
<li><a href="/home">Home</a></li>
<li><a href="/books">Books</a></li>
<li><a href="/authors">Authors</a></li>
</ul>
{% endblock %}
{% extends 'base.html' %} {% block content %}
{% extends 'base.html' %}
{% block title %} My Favorite Books {% endblock %}
{% block content %}
<h1>Justin' Favorite Books</h1>
<ul>
{% for book in bookList %}
<a><li>{{book.title}}</li></a>
{% for object in object_list %}
<a href="{{object.get_absolute_url}}"><li>{{object.title}}</li></a>
{% endfor %}
</ul>
<ul>
<li><a href="/home">Home</a></li>
<li><a href="/authors">Authors</a></li>
</ul>
{% endblock %}
......@@ -6,4 +6,8 @@
love reading horror, biographies, and more. Thanks!
</p>
<ul>
<li><a href="/books">Books</a></li>
<li><a href="/authors">Authors</a></li>
</ul>
{% endblock %}
from django.urls import path
from .views import *
from .views import (
index,
BookListView,
BookDetailView,
)
urlpatterns = [
path("home/", index, name="home"),
path("books/", books, name="books"),
path(
"books/",
BookListView.as_view(),
name="book-list",
),
path("books/<int:pk>/detail", BookDetailView.as_view(), name="book-detail"),
]
......@@ -22,8 +22,14 @@ def books(request):
)
class BookDetailView(View):
class BookListView(ListView):
model = Books
template_name = "bookshelf/books.html"
class BookDetailView(DetailView):
model = Books
template_name = "bookshelf/book_details.html"
# class BooksView(View):
......
......@@ -10,9 +10,5 @@
<body>
<div id="content">{% block content %}{% endblock %}</div>
{% block scripts %}{% endblock %}
<ul>
<li><a href="/books">Books</a></li>
<li><a href="/authors">Authors</a></li>
</ul>
</body>
</html>
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