Commit 9abe4c6b authored by Jayson Lim's avatar Jayson Lim

Implemented the base, home, books, and book_details templates following the...

Implemented the base, home, books, and book_details templates following the specifications also finalized url configurations and populated models
parent 146a6cd4
# Generated by Django 3.2 on 2023-03-28 12:09
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('bookshelf', '0002_rename_books_book'),
]
operations = [
migrations.RenameModel(
old_name='Book',
new_name='Books',
),
]
from django.db import models from django.db import models
from django.urls import reverse
class Author(models.Model): class Author(models.Model):
first_name = models.CharField(max_length=50, default="") first_name = models.CharField(max_length=50, default="")
...@@ -8,7 +9,11 @@ class Author(models.Model): ...@@ -8,7 +9,11 @@ class Author(models.Model):
bio = models.TextField(max_length=700) bio = models.TextField(max_length=700)
def __str__(self): def __str__(self):
return '{}, {}'.format(self.first_name, self.last_name) return '{} {}'.format(self.first_name, self.last_name)
def get_absolute_url(self):
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="")
...@@ -21,3 +26,6 @@ class Books(models.Model): ...@@ -21,3 +26,6 @@ class Books(models.Model):
def __str__(self): def __str__(self):
return self.title return self.title
def get_absolute_url(self):
return reverse('bookshelf:books-detail', kwargs={'pk': self.pk})
{% 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.title }}</h3>
<h1>{{ object.title }}</h1>
<ul>
<li>
<h3>
<a href="{{ object.get_absolute_url }}">
{{ object.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>
{% 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 Books</h3>
<h1>Jayson's Favorite Books:</h1>
<ul>
{% for object in object_list %}
<li>
<h3>
<a href="{{ object.get_absolute_url }}">
{{ object.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 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>
<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>
{% endblock %} {% endblock %}
\ No newline at end of file
from django.urls import path from django.urls import path
from .views import home_view, BooksPageView from . import views
from django.views.generic.list import ListView from .views import home_view, BooksListView, AuthorsListView, BooksDetailView, AuthorsDetailView
from django.views.generic.detail import DetailView
urlpatterns = [ urlpatterns = [
#path('', index, name='index'), path('home/', home_view, name='home'),
path('home', home_view, name='home'), path('books/', BooksListView.as_view(), name='books'),
path('books', BooksPageView.as_view(), name='books'), path('authors/', AuthorsListView.as_view(), name='authors'),
path('books/<int:pk>', BooksDetailView.as_view(), name='books-detail'),
path('authors/<int:pk>', AuthorsDetailView.as_view(), name='authors-detail'),
] ]
app_name = "bookshelf" app_name = "bookshelf"
from django.shortcuts import render from django.shortcuts import render
from django.http import HttpResponse from django.http import HttpResponse
from django.views import View from django.views import View
from django.views.generic.list import ListView
from django.views.generic.detail import DetailView
from .models import Books, Author
def home_view(request): def home_view(request):
return render(request, 'home.html') return render(request, 'bookshelf/home.html')
class BooksListView(ListView):
model = Books
template_name = 'bookshelf/books.html'
class AuthorsListView(ListView):
model = Author
template_name = 'bookshelf/authors.html'
class BooksDetailView(DetailView):
model = Books
template_name = 'bookshelf/book_details.html'
class AuthorsDetailView(DetailView):
model = Author
template_name = 'bookshelf/author_details.html'
class BooksPageView(View):
def get(request):
return render(request, 'bookshelf/books.html')
...@@ -18,6 +18,6 @@ from django.urls import include, path ...@@ -18,6 +18,6 @@ from django.urls import include, path
from bookshelf import views from bookshelf import views
urlpatterns = [ urlpatterns = [
path('bookshelf/', include('bookshelf.urls', namespace="bookshelf")), path('', include('bookshelf.urls', namespace="bookshelf")),
path('admin/', admin.site.urls), path('admin/', admin.site.urls),
] ]
\ No newline at end of file
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