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