Commit a566fc1e authored by Mavrick Jordan Lee's avatar Mavrick Jordan Lee

Added BookDetails cbv in views and its corresponding book_details.html. Made...

Added BookDetails cbv in views and its corresponding book_details.html. Made minor tweaks in models and book template.
parent f2888102
...@@ -25,4 +25,4 @@ class Book(models.Model): ...@@ -25,4 +25,4 @@ class Book(models.Model):
return self.title return self.title
def get_absolute_url(self): def get_absolute_url(self):
return reverse('bookshelf:books-detail', kwargs={'pk': self.pk}) return reverse('bookshelf:book-detail', kwargs={'pk': self.pk})
\ No newline at end of file \ No newline at end of file
{% extends 'base.html' %}
{% block title %}{{ object.title }}{% endblock %}
{% block content %}
<h1>{{ object.title }}</h1>
<p>
{{ object.author }}<br>
{{ object.publisher }}<br>
{{ object.year_published }}<br>
{{ object.ISBN }}<br>
{{ object.blurb }}<br>
</p>
<a href="{% url 'bookshelf:home' %}">Home</a>
&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp
<a href="{% url 'bookshelf:books' %}">Books</a>
&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp
<a href="{% url 'bookshelf:authors' %}">Authors</a>
{% endblock %}
\ No newline at end of file
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
<ul> <ul>
{% for object in object_list %} {% for object in object_list %}
<li> <li>
<a href="{{ object.get_absolute_url }}"> {{ object }}</a> <a href="{{ object.get_absolute_url }}"> {{ object.title }}</a>
</li> </li>
{% endfor %} {% endfor %}
</ul> </ul>
......
from django.urls import path from django.urls import path
from . import views from . import views
from .views import BooksListView, BooksDetailView from .views import BooksListView, BookDetailsView
urlpatterns = [ urlpatterns = [
path('home/', views.home_view, name = "home"), path('home/', views.home_view, name = "home"),
path('books/', BooksListView.as_view(), name = "books"), path('books/', BooksListView.as_view(), name = "books"),
path('books/<int:pk>', BooksDetailView.as_view(), name = "books-detail"), path('books/<int:pk>/details', BookDetailsView.as_view(), name = "book-detail"),
path('authors/', views.authors_view, name = "authors"), path('authors/', views.authors_view, name = "authors"),
] ]
......
...@@ -18,5 +18,6 @@ class BooksListView(ListView): ...@@ -18,5 +18,6 @@ class BooksListView(ListView):
model = Book model = Book
template_name = 'bookshelf/books.html' template_name = 'bookshelf/books.html'
class BooksDetailView(DetailView): class BookDetailsView(DetailView):
model = Book model = Book
template_name = 'bookshelf/book_details.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