Commit bfcb336e authored by Eldon Dagdag's avatar Eldon Dagdag

Created pages for Home, Books, Authors, & Details

parent ee782a7a
from django.db import models
from django.core.validators import MinValueValidator, MaxValueValidator
from django.urls import reverse
class Author(models.Model):
first_name = models.CharField(max_length=255, default='')
......@@ -10,10 +11,13 @@ class Author(models.Model):
def __str__(self):
return '{} {}'.format(self.first_name, self.last_name)
def get_absolute_url(self):
return reverse('bookshelf:author-details', kwargs={'pk':self.pk})
class Book(models.Model):
title = models.CharField(max_length=255, default='')
author = models.ForeignKey(Author, on_delete=models.CASCADE)
author = models.ForeignKey(Author, on_delete=models.CASCADE, related_name='books')
publisher = models.CharField(max_length=255, default='')
year_published = models.PositiveIntegerField()
ISBN = models.PositiveBigIntegerField(validators=[MinValueValidator(1000000000000), MaxValueValidator(9999999999999)])
......@@ -22,3 +26,5 @@ class Book(models.Model):
def __str__(self):
return '{} by {}'.format(self.title, self.author)
def get_absolute_url(self):
return reverse('bookshelf:book-details', kwargs={'pk':self.pk})
{% extends 'base.html' %}
{% load static %}
{% block title %} {{ object.first_name }} {{ object.last_name }}{% endblock %}
{% block content %}
<html>
<h1>{{ object.first_name }} {{ object.last_name }}</h1>
<body>
<h3>Age: {{ object.age }}</h3>
<h3>Nationality: {{ object.nationality }}</h3>
<h3>Biography: {{ object.bio }}</h3>
<h2>Books by {{ object.first_name }} {{ object.last_name }} I love:</h2>
{% for book in object.books.all %}
<li><a href={{ book.get_absolute_url }}>{{ book.title }}</a></li>
{% endfor %}
</body>
<br>
<a href="/bookshelf/home/">Home</a>
<a href="/bookshelf/books/">Books</a>
<a href="/bookshelf/authors/">Authors</a>
</html>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block title %}My Favorite Authors{% endblock %}
{% block content %}
<html>
<h1>Eldon's Favorite Authors:</h1>
<body>
{% for object in object_list %}
<li>
<a href="{{ object.get_absolute_url }}">
{{ object.first_name }} {{ object.last_name }}
</a>
</li>
{% endfor %}
</body>
<br>
<a href="/bookshelf/home/">Home</a>
<a href="/bookshelf/books/">Books</a>
</html>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block title %} {{ object.title }}{% endblock %}
{% block content %}
<html>
<body>
<h1>{{ object.title }}</h1>
<h2>by <a href="{{ object.author.get_absolute_url }}">{{ object.author }}</a></h2>
<h3>Published by {{ object.publisher }}</h3>
<h3>Published in {{ object.year_published }}</h3>
<h3>ISBN: {{ object.ISBN }}</h3>
<h3>"{{ object.blurb }}"</h3>
</body>
<br>
<a href="/bookshelf/home/">Home</a>
<a href="/bookshelf/books/">Books</a>
<a href="/bookshelf/authors/">Authors</a>
</html>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block title %}My Favorite Books{% endblock %}
{% block content %}
<html>
<h1>Eldon's Favorite Books:</h1>
<body>
{% for object in object_list %}
<li>
<a href="{{ object.get_absolute_url }}">
{{ object.title }}
</a>
</li>
{% endfor %}
</body>
<br>
<a href="/bookshelf/home/">Home</a>
<a href="/bookshelf/authors/">Authors</a>
</html>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block title %}My Favorite Books & Authors{% endblock %}
{% block content %}
<h1>Welcome to Eldon's Database of Favorite Books and Authors!</h1>
<h3>Vibes only here.</h3>
<br>
<a href="/bookshelf/books/">Books</a>
<a href="/bookshelf/authors/">Authors</a>
{% endblock %}
\ No newline at end of file
from django.urls import path
from .views import index
from .views import index_view, home, BookListView, BookDetailView, AuthorListView, AuthorDetailView
urlpatterns = [
path('', index, name='index')
path('home/', home, name='home'),
path('books/', BookListView.as_view(), name='books'),
path('books/<int:pk>/details/', BookDetailView.as_view(), name='book-details'),
path('authors/', AuthorListView.as_view(), name='authors'),
path('authors/<int:pk>/details/', AuthorDetailView.as_view(), name='author-details'),
path('', index_view, name='index'),
]
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 import ListView, DetailView
def index(request):
return HttpResponse('Hello World!')
\ No newline at end of file
from .models import Author, Book
def index_view(request):
return HttpResponse("yes")
def home(request):
return render(request, 'bookshelf/home.html', {'name': 'home'})
class BookListView(ListView):
model = Book
template_name = 'bookshelf/books.html'
class BookDetailView(DetailView):
model = Book
template_name = 'bookshelf/book_details.html'
class AuthorListView(ListView):
model = Author
template_name = 'bookshelf/authors.html'
class AuthorDetailView(DetailView):
model = Author
template_name = 'bookshelf/author_details.html'
# def index_view(request):
# return render(request, 'home.html', {'name': 'home'})
# class HomepageView(View):
# def get(self, request):
# return render(request, 'home.html', {'name': 'home'})
\ No newline at end of file
......@@ -59,7 +59,7 @@ ROOT_URLCONF = 'eldondagdag_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>
<meta charset="UTF-8">
<meta name="viewport" content="width-device-width,initial-scale=1.0">
<link rel="stylesheet" href="style.css">
<title>{% block title %}{% 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