Commit 31c5b183 authored by Jose Gabriel L. Salas's avatar Jose Gabriel L. Salas

implemented templates according to the lab spes.

parent 9c7e633d
Pipeline #3082 canceled with stages
from django.db import models
from django.urls import reverse
# Create your models here.
class Author(models.Model):
......@@ -11,6 +11,9 @@ class Author(models.Model):
def __str__(self):
return '{} {}'.format(self.first_name, self.last_name)
def get_absolute_url(self):
return reverse('bookshelf:authors-detail', kwargs={'pk': self.pk})
class Books(models.Model):
title = models.CharField(max_length=50)
......@@ -27,3 +30,5 @@ class Books(models.Model):
def __str__(self):
return '{} by {}'.format(self.title, self.author)
def get_absolute_url(self):
return reverse('bookshelf:books-detail', kwargs={'pk': self.pk})
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block title %}{{ object }}{% endblock %}
{% block content %}
<h1>{{ object }}</h1>
<br>
{{ object.age }}
<br>
{{object.nationality}}
<br>
{{object.bio}}
<br>
<br>
<h>Books by {{ object }} I love:</h>
<br>
<li>
<a href="/bookshelf/books/{{ object.books.get_absolute_url }}">{{ object.books.title }}</a>
</li>
<br>
<a href="/bookshelf/home/">Home</a>
<a href="/bookshelf/books/">Books</a>
<a href="/bookshelf/authors/">Authors</a>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block title %}My Favorite Authors{% endblock %}
{% block content %}
<h1>Gab's Favorite Authors:</h1>
{% for object in object_list %}
<li> <a href="{{ object.get_absolute_url }}">{{ object }}</a> </li>
{% endfor %}
<a href="/bookshelf/home/">Home</a>
<a href="/bookshelf/books/">Books</a>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block title %}{{ object.title }}{% endblock %}
{% block content %}
<h1>{{ object.title }}</h1>
<br>
<a href="{{ object.author.get_absolute_url }}">{{ object.author }}</a>
<br>
{{object.publisher}}
<br>
{{object.year_published}}
<br>
{{object.ISBN}}
<br>
{{object.blurb}}
<br>
<a href="/bookshelf/home/">Home</a>
<a href="/bookshelf/books/">Books</a>
<a href="/bookshelf/authors/">Authors</a>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block title %}My Favorite Books{% endblock %}
{% block content %}
<h1>Gab's Favorite books:</h1>
{% for object in object_list %}
<li> <a href="{{ object.get_absolute_url }}">{{ object }}</a> </li>
{% endfor %}
<a href="/bookshelf/home/">Home</a>
<a href="/bookshelf/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 Gab's Database of Favorite Books and Authors!</h1>
<p>I typically enjoy reading books with thought provoking topics, horrific themes, and myseterious plots. Authors that specializes in these appeal to me the most.</p>
<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, BooksListView, AuthorListView, BooksDetailView, AuthorDetailView
urlpatterns = [
path('', index, name='index'),
path('home/', index, name='index'),
path('books/', BooksListView.as_view(), name='books-list'),
path('authors/', AuthorListView.as_view(), name='author-list'),
path('books/<int:pk>', BooksDetailView.as_view(), name='books-detail'),
path('authors/<int:pk>', AuthorDetailView.as_view(), name='authors-detail'),
]
app_name = "bookshelf"
\ No newline at end of file
#from django.shortcuts import render
from django.http import HttpResponse
from django.shortcuts import render
from django.views import View
from .models import Books, Author
from django.views.generic.detail import DetailView
from django.views.generic.list import ListView
def index(request):
return HttpResponse('Hello World! This came from the index view')
return render(request, 'home.html', {'name': 'Gab'})
class BooksListView(ListView):
model = Books
class BooksDetailView(DetailView):
model = Books
class AuthorListView(ListView):
model = Author
class AuthorDetailView(DetailView):
model = Author
\ No newline at end of file
......@@ -113,13 +113,16 @@ TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
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
......
<!-- gab_salas_reading/templates/base.html -->
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" href="style.css">
<title>{% block title %}My amazing {{name}} site{% 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