Commit d1b68803 authored by Julia Anishka's avatar Julia Anishka

added authors page and fixed errors in urls.py

parent 76ba223c
......@@ -16,7 +16,11 @@ class Author(models.Model):
return self.first_name + ' ' + self.last_name
def get_absolute_url(self):
return reverse('bookshelf:author-detail', kwargs={'pk': self.pk})
return reverse('bookshelf:author_details', kwargs={'pk': self.pk})
def get_books(self):
books_list = Books.objects.filter(author=self)
return books_list
def verify_ISBN(value):
if value.isdigit() == False:
......@@ -45,8 +49,4 @@ class Books(models.Model):
return self.title
def get_absolute_url(self):
return reverse('bookshelf:books-list', kwargs={'pk': self.pk})
return reverse('bookshelf:book_details', kwargs={'pk': self.pk})
\ No newline at end of file
<!-- This page contains a detailed view of an author's information.-->
{% extends 'base.html' %}
{% block title %} {{ object }} {% endblock %}
{% block header %}
<h2> {{ object }} </h2>
{% endblock %}
{% block body %}
<h4> Age: {{ object.age }} </h4>
<h4> Nationality: {{ object.nationality }} </h4>
<h4> Biography: {{ object.bio }} </h4>
<div>
<h3> Books by {{ object }} I love: </h3>
</div>
<ul>
{% for object in object.get_books %}
<li>
<a href="{{ object.get_absolute_url }}">
{{ object.title }}
</a>
</li>
{% endfor %}
</ul>
<div>
<h5> <a href="/home/"> Home </a>
<a href="/books/"> Books </a>
<a href="/authors/"> Authors </a>
</h5>
</div>
{% endblock %}
\ No newline at end of file
<!--This page contains all authors in a list view.-->
{% extends 'base.html' %}
{% block title %} My Favorite Authors {% endblock %}
{% block header %}
<h1> Nisha's Favorite Authors </h1>
{% endblock %}
{% block content %}
<div>
<ul>
{% for object in object_list %}
<li>
<a href="{{ object.get_absolute_url }}">
{{ object }}
</a>
</li>
{% endfor %}
</ul>
</div>
<h5> <a href="/home/"> Home </a> <a href="/books/"> Books </a></h5>
{% endblock %}
\ No newline at end of file
# This page contains a detailed view of the information from the book.
<!--# This page contains a detailed view of book's information. -->
{% extends 'base.html' %}
{% block title %} {{ book.title }} {% endblock %}
{% block title %} {{ object.title }} {% endblock %}
{% block header %}
<h2> {{ object.title }} </h2>
{% 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>
<h4> {{ object.publisher }} </h4>
<h4> {{ object.year_published }} </h4>
<h4> {{ object.ISBN }} </h4>
<h4> {{ object.blurb }} </h4>
<h5> <a href="/home/"> Home </a>
<a href="/books/"> Books </a>
<a href="/authors/"> Authors </a>
</h5>
{% endblock %}
\ No newline at end of file
# This page contains all books in a list view.
<!--This page contains all books in a list view.-->
{% extends 'base.html' %}
{% block title %} My Favorite Books {% endblock %}
{% block header %}
<h1> Nisha's Favorite Books </h1>
{% endblock %}
{% block content %}
<h3> Nisha's Favorite Books </h3>
<div>
<ul>
{% for book in books_list %}
{% for object in object_list %}
<li>
<a href="{{ book.get_absolute_url }}">
{{ book.title }}
<a href="{{ object.get_absolute_url }}">
{{ object.title }}
</a>
</li>
{% endfor %}
</ul>
</div>
<h5> <a href="{% url 'home' %}"> Home </a> <a href="{% url 'authors'}"> Authors </a></h5>
<h5> <a href="/home/"> Home </a> <a href="/authors/"> Authors </a></h5>
{% endblock %}
\ No newline at end of file
......@@ -9,5 +9,5 @@
emotional and engaging storytelling. The characters in her book are deeply relatable and
she's able to move her readers through genuine dialogues.
</p>
<h5> <a href="{% url 'books' %}"> Books </a> <a href="{% url 'authors'}"> Authors </a></h5>
<a href="/books/"> Books </a> <a href="/authors/"> Authors </a></h5>
{% endblock %}
\ No newline at end of file
......@@ -4,11 +4,11 @@ from . import views
from .views import BooksListView, BooksDetailView, AuthorsListView, AuthorsDetailView
urlpatterns = [
path('home', views.homepage_view, name='home'),
path('books', BooksListView.as_view(), name='books-list'),
path('books/<pk>/details', BooksDetailView.as_view(), name='books-detail'),
path('authors', AuthorsListView.as_view(), name='authors-list'),
path('authors/<pk>/details', AuthorsDetailView.as_view(), name='authors-detail')
path('home/', views.homepage_view, name='home'),
path('books/', BooksListView.as_view(), name='books'),
path('books/<int:pk>/details/', BooksDetailView.as_view(), name='book_details'),
path('authors/', AuthorsListView.as_view(), name='authors'),
path('authors/<int:pk>/details/', AuthorsDetailView.as_view(), name='author_details')
]
app_name = 'bookshelf'
\ No newline at end of file
......@@ -8,21 +8,25 @@ from .models import Author, Books
def homepage_view(request):
authors = Author.objects.all()
books = Books.author.all()
books = Books.objects.all()
context = {
'authors': authors,
'books': books
}
return render(request, 'home.html', context)
return render(request, 'bookshelf/home.html', context)
class BooksListView(ListView):
model = Books
template_name = 'bookshelf/books.html'
class BooksDetailView(DetailView):
model = Books
template_name = 'bookshelf/book_details.html'
class AuthorsListView(ListView):
model = Author
template_name = 'bookshelf/authors.html'
class AuthorsDetailView(DetailView):
model = Author
template_name = 'bookshelf/author_details.html'
......@@ -11,6 +11,7 @@ https://docs.djangoproject.com/en/3.2/ref/settings/
"""
from pathlib import Path
import os
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
......@@ -55,7 +56,7 @@ ROOT_URLCONF = 'nishaespera_reading.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'DIRS': [os.path.join(BASE_DIR, 'templates')],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
......
......@@ -14,8 +14,9 @@ Including another URLconf
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path
from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('bookshelf.urls'))
]
......@@ -4,10 +4,12 @@
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{% block title %} My Favorite Books & Authors {% endblock %}</title>
<title>{% block title %} {% endblock %}</title>
{% block styles %}{% endblock %}
</head>
<body>
<header>{% block header %}{% endblock %}</header>
{% block body %}{% endblock %}
{% block content %}{% endblock %}
{% block scripts %}{% endblock %}
......
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