Commit 1cdb568b authored by Ross Batacan's avatar Ross Batacan

Completed the project.

parent 959a28bf
Pipeline #3085 failed with stages
......@@ -12,10 +12,10 @@ class Author(models.Model):
bio = models.CharField(max_length=700, null=True)
def __str__(self):
return self.first_name
return self.first_name + " " + self.last_name
def get_absolute_url(self):
return self.last_name
return reverse('bookshelf:author-detail', kwargs={'pk': self.pk})
class Books(models.Model):
title = models.CharField(max_length=100, unique=True, null=True)
......@@ -29,5 +29,5 @@ class Books(models.Model):
return self.title
def get_absolute_url(self):
return self.title
return reverse('bookshelf:book-detail', kwargs={'pk': self.pk})
{% extends 'base.html' %}
{% block title %}{{ author.first_name }} {{ author.last_name }}{% endblock %}
{% block content %}
<h1>{{ author.first_name }} {{ author.last_name }}</h1>
<p>
{{ author.age }}<br>
{{ author.nationality }}<br>
{{ author.bio }}<br>
Books by {{ author.first_name }} {{ author.last_name }} I love:
</p>
<ul>
{% for book in author.books_set.all %}
<li>
<a href="{{ book.get_absolute_url }}">{{ book.title }}</a>
</li>
{% endfor %}
</ul>
<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
{% extends 'base.html' %}
{% block title %}My Favorite Authors{% endblock %}
{% block content %}
<h1>Ross' Favorite Authors:</h1>
<ul>
{% for author in author_list %}
<li>
<a href="{{ author.get_absolute_url }}"> {{ author.first_name }} {{ author.last_name }} </a>
</li>
{% endfor %}
</ul>
<a href="{% url 'bookshelf:home' %}">Home</a>
&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp
<a href="{% url 'bookshelf:books' %}">Books</a>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% block title %}{{ books.title }}{% endblock %}
{% block content %}
<h1>{{ books.title }}</h1>
<p>
<a href="{{ books.author.get_absolute_url }}">{{ books.author }} </a><br>
{{ books.publisher }}<br>
{{ books.year_published }}<br>
{{ books.ISBN }}<br>
{{ books.blurb }}<br>
</p>
<a href="{% url 'bookshelf:home' %}">Home</a>
&nbsp&nbsp&nbsp&nbsp
<a href="{% url 'bookshelf:books' %}">Books</a>
&nbsp&nbsp&nbsp&nbsp
<a href="{% url 'bookshelf:authors' %}">Authors</a>
{% endblock %}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>The Books</title>
</head>
<body>
{% extends 'base.html' %}
{% block title %}My Favorite Books & Authors{% endblock %}
{% block content %}
<h1>Ross' Favorite Books:</h1>
<ul>
{% for book in books_list %}
<li>
<a href="{{ book.get_absolute_url }}"> {{ book.title }}</a>
</li>
{% endfor %}
</ul>
<a href="{% url 'bookshelf:home' %}">Home</a>
&nbsp&nbsp&nbsp&nbsp
<a href="{% url 'bookshelf:authors' %}">Authors</a>
{% endblock %}
</body>
</html>
\ No newline at end of file
......@@ -4,7 +4,8 @@
<h1>Welcome to Ross's Database of Favorite Books and Authors!</h1>
<h3>I like books, books, and books. My recent read was Tuesdays with Morrie by
Mitch Albom</h3>
<a href="{% url 'bookshelf:books' %}">Books</a> <br>
<a href="{% url 'bookshelf:books' %}">Books</a>
&nbsp&nbsp&nbsp&nbsp
<a href="{% url 'bookshelf:authors' %}">Authors</a>
{% endblock %}
{% endblock %}
......@@ -8,7 +8,7 @@ urlpatterns = [
path('books/', BooksListView.as_view(), name = "books"),
path('books/<int:pk>/details/', BooksDetailsView.as_view(), name = "book-detail"),
path('authors/', AuthorsListView.as_view(), name = "authors"),
path('authors/<int:pk>/details', AuthorDetailsView.as_view(), name = "author-detail"),
path('authors/<int:pk>/details/', AuthorDetailsView.as_view(), name = "author-detail"),
]
app_name = 'bookshelf'
......@@ -14,7 +14,7 @@ class BooksListView(ListView):
template_name = 'bookshelf/books.html'
class BooksDetailsView(DetailView):
model = Author
model = Books
template_name = 'bookshelf/book_details.html'
class AuthorsListView(ListView):
......@@ -23,4 +23,4 @@ class AuthorsListView(ListView):
class AuthorDetailsView(DetailView):
model = Author
template_name = 'bookshelf/author_details'
\ No newline at end of file
template_name = 'bookshelf/author_details.html'
\ No newline at end of file
......@@ -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 = 'rossybossy_reading.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'DIRS': [os.path.join(BASE_DIR, 'templates')],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
......
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