Add templates, ListViews, and DetailViews

parent 0930752d
from django.db import models
from django.urls import reverse
# Create your models here.
class Author(models.Model):
......@@ -11,6 +12,9 @@ class Author(models.Model):
def __str__(self):
return "{} {}".format(self.first_name, self.last_name)
def get_absolute_url(self):
return reverse('bookshelf:author-detail', kwargs={'pk': self.pk})
class Books(models.Model):
title = models.CharField(max_length=100)
......@@ -28,3 +32,6 @@ class Books(models.Model):
def __str__(self):
return "{}".format(self.title)
def get_absolute_url(self):
return reverse('bookshelf:books-detail', kwargs={'pk': self.pk})
{% extends 'base.html' %}
{% load static %}
{% block title %} {{object}} {% endblock %}
{% block content %}
<h1> {{object}} </h1><br>
<ul>
<li> <b>Age:</b> {{object.age}} </li>
<li> <b>Nationality:</b> {{object.nationality}} </li>
<li> <b>Bio:</b> {{object.bio}} </li>
</ul>
<br><hr><br><br>
<a href="../home/">Home</a> &nbsp; <a href="../authors/">Authors</a> &nbsp; <a href="../books/">Books</a>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block title %} My Favorite Authors {% endblock %}
{% block content %}
<h1> Joaqs' Favorite Authors! </h1><br>
<ul>
{% for object in object_list %}
<li>
<a href="{{ object.get_absolute_url }}"> {{object}} </a>
</li>
{% endfor %}
</ul>
<br><hr><br><br>
<a href="../home/">Home</a> &nbsp; <a href="../books/">Books</a>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block title %} {{object}} {% endblock %}
{% block content %}
<h1> {{object}} </h1><br>
<ul>
<li> <b>Author:</b> <a href="object.author.get_absolute_url">{{object.author}}</a> </li>
<li> <b>Publisher:</b> {{object.publisher}} </li>
<li> <b>Year Published:</b> {{object.year_published}} </li>
<li> <b>ISBN:</b> {{object.ISBN}} </li>
<li> <b>Blurb:</b> {{object.blurb}} </li>
</ul>
<br><hr><br><br>
<a href="../home/">Home</a> &nbsp; <a href="../authors/">Authors</a> &nbsp; <a href="../books/">Books</a>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block title %} My Favorite Books {% endblock %}
{% block content %}
<h1> Joaqs' Favorite Books! </h1><br>
<ul>
{% for object in object_list %}
<li>
<a href="{{ object.get_absolute_url }}"> {{object}} </a>
</li>
{% endfor %}
</ul>
<br><hr><br><br>
<a href="../home/">Home</a> &nbsp; <a href="../authors/">Authors</a>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block title %} My Favorite Books & Authors {% endblock %}
{% block content %}
<h1> Welcome to Joaqs' Database of Favorite Books & Authors! </h1><h6> That is definitely not just the list of best-selling books on Wikipedia! </h6><br>
<p> Hi! My name is Joaqs! I usually like science fiction books and non-fiction books, but my favorite book series is A Song of Ice and Fire by George R. R. Martin. </p>
<p> While I don't have a favorite author, I usually enjoy books that are experimental or have good twists. </p>
<br><hr><br><br>
<a href="../authors/">Authors</a> &nbsp; <a href="../books/">Books</a>
{% endblock %}
\ No newline at end of file
from django.urls import path
from .views import index
from .views import HomeView, AuthorListView, AuthorDetailView, BooksListView, BooksDetailView
urlpatterns = [
path('', index, name='index'),
path('', HomeView, name='index'),
path('authors', AuthorListView.as_view(), name='author-list'),
path('authors/<int:pk>/details', AuthorDetailView.as_view(), name='author-detail'),
path('books', BooksListView.as_view(), name='books-list'),
path('books/<int:pk>/details', BooksDetailView.as_view(), name='books-detail'),
]
# This might be needed, depending on your Django version
......
from django.shortcuts import render
from django.http import HttpResponse
from django.views import View
from django.views.generic.detail import DetailView
from django.views.generic.list import ListView
def index(request):
return HttpResponse('placeholder view')
from .models import Author, Books
def HomeView(request):
return render(request, 'bookshelf/home.html/')
class AuthorListView(ListView):
model = Author
class AuthorDetailView(DetailView):
model = Author
class BooksListView(ListView):
model = Books
class BooksDetailView(DetailView):
model = Books
......@@ -59,7 +59,7 @@ ROOT_URLCONF = 'joaqscrisologo_reading.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'DIRS': [os.path.join(BASE_DIR, 'templates')],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
......@@ -123,6 +123,7 @@ USE_TZ = True
# https://docs.djangoproject.com/en/3.2/howto/static-files/
STATIC_URL = '/static/'
STATICFILES_DIRS = [os.path.join(BASE_DIR, 'static')]
# Default primary key field type
# https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field
......
......@@ -15,8 +15,13 @@ Including another URLconf
"""
from django.contrib import admin
from django.urls import include, path
from bookshelf import views
urlpatterns = [
path('bookshelf/', include('bookshelf.urls', namespace="bookshelf")),
path('admin/', admin.site.urls),
path('home/', views.HomeView, name='home'),
path('authors/', views.AuthorListView.as_view(), name='authors-list'),
path('books/', views.BooksListView.as_view(), name='books-list'),
]
body {
background-color: black;
color: white;
\ No newline at end of file
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" href="style.css">
<title>{% block title %}My Favorite Books & Authors{% endblock %}</title>
{% block styles %}{% endblock %}
</head>
<body>
<div id="content">
{% block content %}{% endblock %}
</div>
{% block scripts %}{% endblock %}
</body>
</html>
\ 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