Commit 430435c2 authored by Ron Rodillas's avatar Ron Rodillas

Created and implemented the templates

parent bcb75d19
Pipeline #3122 failed with stages
from django.db import models
from django.urls import reverse
# Create your models here.
class Author(models.Model):
......@@ -10,6 +11,12 @@ class Author(models.Model):
def __str__(self):
return (self.first_name + " " + self.last_name)
def get_name(self):
return self.__str__()
def get_absolute_url(self):
return reverse('bookshelf:AuthorDetailView', kwargs={'pk': self.pk})
class Books(models.Model):
title = models.CharField(max_length=100)
......@@ -20,4 +27,10 @@ class Books(models.Model):
blurb = models.TextField()
def __str__(self):
return self.title
\ No newline at end of file
return self.title
def get_name(self):
return self.__str__()
def get_absolute_url(self):
return reverse('bookshelf:BookDetailView', kwargs={'pk': self.pk})
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block title %}
{{object.get_name}}
{% endblock %}
{% block styles %}
<style>
p1 {
line-height: 1.5;
}
</style>
{% endblock %}
{% block content %}
<h1>{{object.get_name}}</h1>
<p1>
{{object.age}}<br>
{{object.nationality}}<br>
</p1>
{{object.bio}}<br>
<h2>Books by {{object.get_name}} I love:</h2>
<p2></p2>
<div>
<a href="{% url 'bookshelf:home' %}"> Home</a>
&nbsp;&nbsp;&nbsp;
<a href="{% url 'bookshelf:BooksView' %}"> Books</a>
&nbsp;&nbsp;&nbsp;
<a href="{% url 'bookshelf:AuthorsView' %}"> Authors</a>
</div>
{% endblock %}
{% extends 'base.html' %}
{% load static %}
{% block title %}
My Favorite Authors
{% endblock %}
{% block styles %}
<style>
</style>
{% endblock %}
{% block content %}
<h1>
Ron's Favorite Authors: <br>
</h1>
<p1>
{% for author in authors %}
<a href="{{author.get_absolute_url}}"> {{author.get_name}}</a><br>
{% endfor %}
</p1>
<br>
<div>
<a href="{% url 'bookshelf:home' %}"> Home</a>
&nbsp;&nbsp;&nbsp;
<a href="{% url 'bookshelf:BooksView' %}"> Books</a>
</div>
{% endblock %}
{% extends 'base.html' %}
{% load static %}
{% block title %}
My Favorite Books
{% endblock %}
{% block styles %}
<style>
</style>
{% endblock %}
{% block content %}
<h1>
Ron's Favorite Books: <br>
</h1>
<p1>
{% for book in books %}
<a href="{{book.get_absolute_url}}"> {{book.get_name}}</a><br>
{% endfor %}
</p1>
<br>
<div>
<a href="{% url 'bookshelf:home' %}"> Home</a>
&nbsp;&nbsp;&nbsp;
<a href="{% url 'bookshelf:AuthorsView' %}"> Authors</a>
</div>
{% endblock %}
{% extends 'base.html' %}
{% load static %}
{% block title %}
{{object.title}}
{% endblock %}
{% block styles %}
<style>
p1 {
line-height: 1.5;
}
</style>
{% endblock %}
{% block content %}
<h1>{{object}}</h1>
<h2><a href="{{object.author.get_absolute_url}}"> {{object.author}}</a></h2>
<p1>
{{object.publisher}}<br>
{{object.year_published}}<br>
{{object.ISBN}}<br>
</p1>
{{object.blurb}}<br>
<br>
<div>
<a href="{% url 'bookshelf:home' %}"> Home</a>
&nbsp;&nbsp;&nbsp;
<a href="{% url 'bookshelf:BooksView' %}"> Books</a>
&nbsp;&nbsp;&nbsp;
<a href="{% url 'bookshelf:AuthorsView' %}"> Authors</a>
</div>
{% endblock %}
{% extends 'base.html' %}
{% load static %}
{% block title %}
My Favorite Books & Authors
{% endblock %}
{% block styles %}
<style>
h1 {
text-align:center
}
p {
text-align:center
}
div {
text-align:center
}
</style>
{% endblock %}
{% block content %}
<h1>
Welcome to Ron's Database of <br>
Favorite Books and Authors!
</h1>
<p>
I like reading fiction fantasy novels <br>
I am also a fan of Japanese mangas
</p>
<br>
<div>
<a href="{% url 'bookshelf:BooksView' %}"> Books</a>
&nbsp;&nbsp;&nbsp;
<a href="{% url 'bookshelf:AuthorsView' %}"> Authors</a>
</div>
{% endblock %}
\ No newline at end of file
from django.urls import path
from .views import index
from .views import home, BooksView, AuthorsView, BookDetailView, AuthorDetailView
urlpatterns = [
# path('', index, name='index'),
path('', home, name='home'),
path('books/', BooksView.as_view(), name='BooksView'),
path('authors/', AuthorsView.as_view(), name='AuthorsView'),
path('books/<int:pk>/details', BookDetailView.as_view(), name='BookDetailView'),
path('authors/<int:pk>/details', AuthorDetailView.as_view(), name='AuthorDetailView')
]
app_name="bookshelf"
\ No newline at end of file
from django.shortcuts import render
from django.http import HttpResponse
from django.views import View
from django.views.generic.detail import DetailView
from .models import *
# Create your views here.
def home(request):
return render(request,"bookshelf/home.html")
class BooksView(View):
def get(self, request):
books = Books.objects.all()
return render(request,"bookshelf/books.html", {'books': books})
class AuthorsView(View):
def get(self, request):
authors = Author.objects.all()
return render(request,"bookshelf/authors.html", {'authors': authors})
class BookDetailView(DetailView):
model = Books
class AuthorDetailView(DetailView):
model = Author
\ No newline at end of file
......@@ -11,7 +11,7 @@ https://docs.djangoproject.com/en/4.1/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 +55,7 @@ ROOT_URLCONF = 'ronrodillas_reading.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'DIRS': [os.path.join(BASE_DIR, 'templates')],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
......@@ -116,8 +116,8 @@ USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/4.1/howto/static-files/
STATIC_URL = 'static/'
STATIC_URL = '/static/'
STATICFILES_DIRS = [os.path.join(BASE_DIR, 'static')]
# Default primary key field type
# https://docs.djangoproject.com/en/4.1/ref/settings/#default-auto-field
......
......@@ -17,6 +17,6 @@ from django.contrib import admin
from django.urls import include, path
urlpatterns = [
# path('bookshelf/', include('bookshelf.urls', namespace="bookshelf")),
path('home/', include('bookshelf.urls', namespace="home")),
path('admin/', admin.site.urls),
]
<html lang="en">
<head>
<link rel="stylesheet" href="style.css">
<title>{% block title %}My amazing site{% endblock %}</title>
{% block styles %}{% endblock %}
</head>
<body>
<div id="content">
{% block content %}{% endblock %}
</div>
</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