Commit 37caf373 authored by Gabriel Limbaga's avatar Gabriel Limbaga

implemented templates

parent 9fe488f7
from django.db import models from django.db import models
from django.urls import reverse
# Create your models here. # Create your models here.
class Author(models.Model): class Author(models.Model):
...@@ -12,6 +12,9 @@ class Author(models.Model): ...@@ -12,6 +12,9 @@ class Author(models.Model):
def __str__(self): def __str__(self):
return str(self.first_name + ' ' + self.last_name) return str(self.first_name + ' ' + self.last_name)
def get_absolute_url(self):
return reverse('bookshelf:authors-details', kwargs={'pk': self.pk})
class Books(models.Model): class Books(models.Model):
title = models.CharField(max_length = 50) title = models.CharField(max_length = 50)
author = models.ForeignKey(Author, on_delete = models.CASCADE) author = models.ForeignKey(Author, on_delete = models.CASCADE)
...@@ -21,4 +24,7 @@ class Books(models.Model): ...@@ -21,4 +24,7 @@ class Books(models.Model):
blurb = models.TextField(blank=True) blurb = models.TextField(blank=True)
def __str__(self): def __str__(self):
return self.title return self.title
\ No newline at end of file
def get_absolute_url(self):
return reverse('bookshelf:books-details', kwargs={'pk': self.pk})
\ No newline at end of file
{% extends 'base.html' %}
{% block title %}My Favorite Authors{% endblock %}
{% block content %}
<h1>Gabes's Favorite Authors: </h1>
<ul>
{% for object in object_list %}
<li>
<a href="{{ object.get_absolute_url }}">
{{object}}
</a>
</li>
{% endfor %}
</ul>
<a href="/bookshelf/home/">Home</a>
<a href="/bookshelf/books/">Books</a>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% block title %}{{object}}{% endblock %}
{% block content %}
<h1>{{ object }}</h1>
Age: {{object.age}} <br>
Nationality: {{object.nationality}} <br>
{{object.bio}} <br>
Books by {{object}} I love:
<ul>
{% for books in object.books_set.all %}
<li>
<a href="/bookshelf/books/{{books.pk}}/details">{{books.title}}</a>
</li>
{%endfor%}
</ul>
<a href="/bookshelf/home/">Home</a> &nbsp; &nbsp;
<a href="/bookshelf/books/">Books</a> &nbsp; &nbsp;
<a href="/bookshelf/authors/">Authors</a>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% block title %}My Favorite Books{% endblock %}
{% block content %}
<h1>Gabes's Favorite Books: </h1>
<ul>
{% for object in object_list %}
<li>
<a href="{{ object.get_absolute_url }}">
{{object}}
</a>
</li>
{% endfor %}
</ul>
<a href="/bookshelf/home/">Home</a>&nbsp; &nbsp;
<a href="/bookshelf/authors/">Authors</a>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% block title %}{{object}}{% endblock %}
{% block content %}
<h1>{{ object.title }}</h1>
Author: <a href="{{ object.author.get_absolute_url }}"> {{object.author}} </a> <br>
Publisher: {{object.publisher}} <br>
Year Published: {{object.year_published}} <br>
ISBN: {{object.ISBN}} <br>
{{object.blurb}}<br>
<a href="/bookshelf/home/">Home</a>&nbsp; &nbsp;
<a href="/bookshelf/books/">Books</a>&nbsp; &nbsp;
<a href="/bookshelf/authors/">Authors</a>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% block title %}My Favorite Books and Authors{% endblock %}
{% block content%}
<h1> Welcome to Gabes's Database of Favorite Books and Authors</h1>
Ever since I started Reading, I have been drawn to fiction and preferred to be wicked away
into fictional worlds. The books by Rick Riordan and J.K. Rowling were among my favorite to read
when I was little. As I grew up, books that had lessons I could use in real life such as the financial insight
given by Rich Dad, Poor Dad by Robert Kiyosaki really gave me more to think about as I started to get older.<br>
<a href="/bookshelf/books/">Books</a> &nbsp; &nbsp;
<a href="/bookshelf/authors/">Authors</a>
{% endblock %}
\ No newline at end of file
from django.urls import path from django.urls import path
from .views import index from .views import home, BooksListView, BooksDetailView, AuthorListView, AuthorDetailView
urlpatterns = [ urlpatterns = [
path('', index, name="index") path('home/', home, name="home"),
path('books/', BooksListView.as_view(), name="books-list"),
path('books/<int:pk>/details/', BooksDetailView.as_view(), name="books-details"),
path('authors/', AuthorListView.as_view(), name='author-list'),
path('authors/<int:pk>/details/', AuthorDetailView.as_view(), name="authors-details")
] ]
app_name = "bookshelf" app_name = "bookshelf"
\ No newline at end of file
from django.http import HttpResponse from django.shortcuts import render
from django.views import View
from django.views.generic.list import ListView
from django.views.generic.detail import DetailView
from .models import Books, Author
# Create your views here.
def home(request):
return render(request, 'bookshelf/home.html')
class BooksListView(ListView):
model = Books
template_name = "bookshelf/books.html/"
# Create your views here. class BooksDetailView(DetailView):
def index(request): model = Books
return HttpResponse("hello") template_name = "bookshelf/books_detail.html/"
\ No newline at end of file
class AuthorListView(ListView):
model = Author
template_name = "bookshelf/authors.html/"
class AuthorDetailView(DetailView):
model = Author
template_name = "bookshelf/authors_detail.html/"
\ No newline at end of file
...@@ -55,7 +55,7 @@ ROOT_URLCONF = 'gabeslimbaga_reading.urls' ...@@ -55,7 +55,7 @@ ROOT_URLCONF = 'gabeslimbaga_reading.urls'
TEMPLATES = [ TEMPLATES = [
{ {
'BACKEND': 'django.template.backends.django.DjangoTemplates', 'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [], 'DIRS': [BASE_DIR / 'templates'],
'APP_DIRS': True, 'APP_DIRS': True,
'OPTIONS': { 'OPTIONS': {
'context_processors': [ 'context_processors': [
......
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>
<link rel="stylesheet" href="style.css">
<title>{% block title %}My amazing site{% endblock %}</title> <title>{% block title %}My amazing site{% endblock %}</title>
{% block styles %}{% endblock %} {% block styles %}{% endblock %}
</head> </head>
<body> <body>
<div id="content">
{% block content %}{% endblock %} {% block content %}{% endblock %}
</div>
{% block scripts %}{% endblock %} {% block scripts %}{% endblock %}
</body> </body>
</html> </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