Commit 5bffd121 authored by Jayson Lim's avatar Jayson Lim

Finalized home template and added reverse functions in views tog et the urls...

Finalized home template and added reverse functions in views tog et the urls for the authors and books views
parent 9abe4c6b
......@@ -15,6 +15,7 @@ class Author(models.Model):
return reverse('bookshelf:authors-detail', kwargs={'pk': self.pk})
class Books(models.Model):
title = models.CharField(max_length=50, default="")
author = models.ForeignKey(Author, on_delete=models.CASCADE, related_name='books')
......
{% extends 'base.html' %}
{% load static %}
{% block title %}This is the page title{% endblock %}
{% block content %}
<h1>Hello World. This is the content</h1>
<h3>{{ object }}</h3>
<h1>{{ object }}</h1>
<ul>
<li><h3>{{ object.age }}</h3></li>
<li><h3>{{ object.nationality }}</h3></li>
<li><h3>{{ object.bio }}</h3></li>
</ul>
<h1>Books by {{ object }} I love:</h1>
<ul>
{% for book in books %}
<li>
<h3>
<a href="{{ book.get_absolute_url }}">
{{ book.title }}
</a>
</h3>
</li>
{% endfor %}
</ul>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block title %}This is the page title{% endblock %}
{% block content %}
<h1>Hello World. This is the content</h1>
<h3>My Favourite Authors</h3>
<h1>Jayson's Favorite Authors:</h1>
<ul>
{% for object in object_list %}
<li>
<h3>
<a href="{{ object.get_absolute_url }}">
{{ object }}
</a>
</h3>
</li>
{% endfor %}
</ul>
{% endblock %}
\ No newline at end of file
......@@ -8,13 +8,16 @@
<ul>
<li>
<h3>
<a href="{{ object.get_absolute_url }}">
{{ object.author }}
</a></h3></li>
<a href="{{ author.get_absolute_url }}">{{ author }}</a>
</h3>
</li>
<li><h3>{{ object.publisher }}</h3></li>
<li><h3>{{ object.year_published }}</h3></li>
<li><h3>{{ object.ISBN }}</h3></li>
<li><h3>{{ object.blurb }}</h3></li>
</ul>
<div style="display: flex; justify-content: space-between;">
<a href="{% url 'bookshelf:home' %}">Home</a>
<a href="{% url 'bookshelf:authors' %}">Authors</a>
</div>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block content %}
<h3>My Favourite Books</h3>
<h1>Jayson's Favorite Books:</h1>
......@@ -16,4 +15,8 @@
</li>
{% endfor %}
</ul>
<div style="display: flex; justify-content: space-between;">
<a href="{% url 'bookshelf:home' %}">Home</a>
<a href="{% url 'bookshelf:authors' %}">Authors</a>
</div>
{% endblock %}
\ No newline at end of file
......@@ -2,25 +2,29 @@
{% load static %}
{% block content %}
<style>
h3 {
border-bottom: 2px solid black;
}
</style>
<h3>My Favourite Books & Authors</h3>
<h1>Welcome to Jayson's Database of Favorite Books and Authors!</h1>
<h2>Genres</h2>
<p>As someone who loves reading, I'm particularly drawn to four genres:</p>
<ul>
<li>Fiction - lets me explore imaginative worlds and stories, from romance to sci-fi</li>
<li>Drama - presents human conflicts and emotions in a thought-provoking way</li>
<li>Thriller - keeps me on the edge of my seat with suspenseful and exciting plots, be it crime or psychological thrillers</li>
<li>Action-Adventure - offers fast-paced stories that immerse me in exciting journeys, from spy novels to epic fantasy tales</li>
</ul>
<p>I absolutely love to read and I can't get enough of four genres in particular:
fiction, drama, thriller, and action-adventure. Fiction is just awesome because
it's so broad and diverse. I can explore all kinds of cool worlds and stories,
whether they're about love, sci-fi, or classic literature. Drama is another one
of my faves because it tackles serious human emotions and conflicts in a thought-provoking way.
I find thrillers particularly exciting, with their suspenseful and gripping plots,
whether they involve crime or psychological plot-twists. And lastly, I love diving
into worlds filled with action-adventure, from spy stories to crazy fantasy realms.</p>
<h2>Favorite Authors</h2>
<p>I enjoy the works of:</p>
<ul>
<li>George R.R. Martin</li>
<li>Robert Ludlum</li>
<li>J.K. Rowling</li>
<li>Dan Brown</li>
<li>John Grisham</li>
<li>Tom Clancy</li>
<li>J.R.R. Tolkien</li>
</ul>
<p>I enjoy the works of: George R.R. Martin, Robert Ludlum, J.K. Rowling, Dan Brown,
John Grisham, Tom Clancy, and J.R.R. Tolkien.</p>
<div style="display: flex; justify-content: space-between;">
<a href="{% url 'bookshelf:books' %}">Books</a>
<a href="{% url 'bookshelf:authors' %}">Authors</a>
</div>
{% endblock %}
\ No newline at end of file
......@@ -4,13 +4,23 @@ from django.views import View
from django.views.generic.list import ListView
from django.views.generic.detail import DetailView
from .models import Books, Author
from django.urls import reverse
def home_view(request):
return render(request, 'bookshelf/home.html')
authors_url = reverse('bookshelf:authors')
books_url = reverse('bookshelf:books')
context = {'authors_url': authors_url, 'books_url': books_url}
return render(request, 'bookshelf/home.html', context)
class BooksListView(ListView):
model = Books
template_name = 'bookshelf/books.html'
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['home_url'] = reverse('bookshelf:home')
context['authors_url'] = reverse('bookshelf:authors')
return context
class AuthorsListView(ListView):
model = Author
......@@ -19,10 +29,22 @@ class AuthorsListView(ListView):
class BooksDetailView(DetailView):
model = Books
template_name = 'bookshelf/book_details.html'
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
author = self.object.author
context['author'] = author
return context
class AuthorsDetailView(DetailView):
model = Author
template_name = 'bookshelf/author_details.html'
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
author = self.object
context['books'] = Books.objects.filter(author=author)
return context
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