Commit 5ee8933e authored by justin's avatar justin

Created detail HTML pages for each book

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