Commit 5e90bd32 authored by rachbit's avatar rachbit

created templates and implemented html pages

parent 25677754
# Generated by Django 3.2 on 2023-03-28 13:00
import django.core.validators
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('bookshelf', '0002_auto_20230328_1255'),
]
operations = [
migrations.AlterField(
model_name='book',
name='blurb',
field=models.CharField(max_length=200, validators=[django.core.validators.MinLengthValidator(100)]),
),
]
......@@ -19,7 +19,7 @@ class Book(models.Model):
publisher = models.CharField(max_length=100)
year_published = models.CharField(max_length=4, validators=[RegexValidator(r'^\d{1,10}$')])
ISBN = models.CharField(primary_key=True, max_length=13,validators=[MinLengthValidator(13), RegexValidator(r'^\d{1,10}$')])
blurb = models.CharField(max_length=200)
blurb = models.CharField(max_length=200, validators=[MinLengthValidator(100)])
def __str__(self):
return '{}'.format(self.title)
{% extends 'base.html' %}
{% load static %}
{% block title %}{{object.first_name}}{{object.last_name}}{% endblock %}
{% block content %}
<h1>{{object.title}}</h1>
<ul>
<li>{{object.age}}</li>
<li>{{object.nationality}}</li>
<li>{{object.bio}}</li>
</ul>
<br>
<h2>Books by {{object.first_name}} {{object.last_name}} that I love:</h2>
<ul>
{% for book in object.books.all %}
<li>
<a href="{{ book.get_absolute_url }}">{{book.title}}</a>
</li>
{% endfor %}
</ul>
<div class="container space-evenly">
<a href="/home">Home</a>
<a href="/books">Books</a>
<a href="/authors">Authors</a>
</div>
{% endblock %}
{% extends 'base.html' %}
{% load static %}
{% block title %}My Favorite Authors{% endblock %}
{% block content %}
<h1 class="text-center">Rach's Favorite Authors:</h1>
<br>
<ul>
{% for object in object_list %}
<li>
<a href="{{ object.get_absolute_url }}">
{{ object.first_name }}{{ object.last_name }}
</a>
</li>
{% endfor %}
</ul>
<div class="container space-evenly">
<a href="/home">Home</a>
<a href="/books">Books</a>
</div>
{% endblock %}
{% extends 'base.html' %}
{% load static %}
{% block title %}{{object.title}}{% endblock %}
{% block content %}
<h1>{{object.title}}</h1>
<ul>
<li>
<a href="{{ object.author.get_absolute_url }}">{{object.author}}</a>
</li>
<li>{{object.publisher}}</li>
<li>{{object.year_published}}</li>
<li>{{object.ISBN}}</li>
<li>{{object.blurb}}</li>
</ul>
<br>
<div class="container space-evenly">
<a href="/home">Home</a>
<a href="/books">Books</a>
<a href="/authors">Authors</a>
</div>
{% endblock %}
{% extends 'base.html' %}
{% load static %}
{% block title %}My Favorite Books{% endblock %}
{% block content %}
<h1 class="text-center">Rach's Favorite Books:</h1>
<br>
<ul>
{% for object in object_list %}
<li>
<a href="{{ object.get_absolute_url }}">
{{ object.title }}
</a>
</li>
{% endfor %}
</ul>
<div class="container space-evenly">
<a href="/home">Home</a>
<a href="/authors">Authors</a>
</div>
{% endblock %}
{% extends 'base.html' %}
{% load static %}
{% block title %}My Favorite Books & Authors{% endblock %}
{% block content %}
<h1 class="text-center">Welcome to Rach's Database of Favorite Books and Authors!</h1>
<br>
<p class="text-center">
!! Book !! Review !! I do not like reading that much but these are some of the books I would like to gatekeep.
</p>
<br>
<div class="container space-evenly">
<a href="/books">Books</a>
<a href="/authors">Authors</a>
</div>
{% endblock %}
from django.urls import path
from .views import index
from .views import index, home, BooksView, AuthorsView, BookDetailView, AuthorDetailView
urlpatterns = [
path('', index, name='index'),
path('',index,name='index'),
path('home/',home,name='home'),
path('books/',BooksView.as_view(),name='books'),
path('authors/',AuthorsView.as_view(),name='authors'),
path('books/<int:pk>/details/',BookDetailView.as_view(),name='book_details'),
path('authors/<int:pk>/details/',AuthorDetailView.as_view(),name='author_details')
]
# This might be needed, depending on your Django version
app_name = "bookshelf"
from django.shortcuts import render
from django.http import HttpResponse
from django.views.generic import ListView, DetailView
# Create your views here.
from .models import Author, Book
def index(request):
return HttpResponse('bookshelf view')
return HttpResponse('honk honk')
def home(request):
return render(request, 'bookshelf/home.html', {'name': 'home'})
class BooksView(ListView):
model = Book
template_name = 'bookshelf/books.html'
class BookDetailView(DetailView):
model = Book
template_name = 'bookshelf/book_details.html'
class AuthorsView(ListView):
model = Author
template_name = 'bookshelf/authors.html'
class AuthorDetailView(DetailView):
model = Author
template_name = 'bookshelf/author_details.html'
......@@ -59,7 +59,7 @@ ROOT_URLCONF = 'rachpurisima_reading.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'DIRS': [os.path.join(BASE_DIR, 'templates')],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
......
<!DOCTYPE html>
<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>
{% block scripts %}{% endblock %}
</body>
</html>
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