Commit f02679a0 authored by Julia Anishka's avatar Julia Anishka

added bookslistview and booksdetailview pages

parent 30c8cf6b
...@@ -15,6 +15,9 @@ class Author(models.Model): ...@@ -15,6 +15,9 @@ class Author(models.Model):
def __str__(self): def __str__(self):
return self.first_name + ' ' + self.last_name return self.first_name + ' ' + self.last_name
def get_absolute_url(self):
return reverse('bookshelf:author-detail', kwargs={'pk': self.pk})
def verify_ISBN(value): def verify_ISBN(value):
if value.isdigit() == False: if value.isdigit() == False:
raise ValidationError('ISBN must only be integers.') raise ValidationError('ISBN must only be integers.')
......
# This page contains a detailed view of the information from the book.
{% extends 'base.html' %}
{% block title %} {{ book.title }} {% endblock %}
{% block body %}
<h2> {{ book.title }} </h2>
<h4> <a href="{{ author.get_absolute_url }}">
{{ book.author }}
</a>
</h4>
<h4> {{ book.publisher }} </h4>
<h4> {{ book.year_published }} </h4>
<h4> {{ book.ISBN }} </h4>
<h4> {{ book.blurb }} </h4>
<h5> <a href="{% url 'home' %}"> Home </a>
<a href="{% url 'books' %}"> Books </a>
<a href="{% url 'authors'}"> Authors </a>
</h5>
{% endblock %}
\ No newline at end of file
# This page contains all books in a list view.
{% extends 'base.html' %}
{% block title %} My Favorite Books {% endblock %}
{% block content %}
<h3> Nisha's Favorite Books </h3>
<div>
<ul>
{% for book in books_list %}
<li>
<a href="{{ book.get_absolute_url }}">
{{ book.title }}
</a>
</li>
{% endfor %}
</ul>
</div>
<h5> <a href="{% url 'home' %}"> Home </a> <a href="{% url 'authors'}"> Authors </a></h5>
{% endblock %}
\ No newline at end of file
from django.urls import path from django.urls import path
from . import views from . import views
from .views import BooksListView from .views import BooksListView, BooksDetailView
urlpatterns = [ urlpatterns = [
path('home', views.homepage_view, name='home'), path('home', views.homepage_view, name='home'),
path('books', BooksListView.as_view(), name='books-list') path('books', BooksListView.as_view(), name='books-list'),
path('books/<pk>/details', BooksDetailView.as_view(), name='books-detail'),
] ]
......
...@@ -17,3 +17,6 @@ def homepage_view(request): ...@@ -17,3 +17,6 @@ def homepage_view(request):
class BooksListView(ListView): class BooksListView(ListView):
model = Books model = Books
class BooksDetailView(DetailView):
model = Books
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