Commit b46dccb8 authored by Elaiza Bolislis's avatar Elaiza Bolislis

Created necessary pages and templates to display the database

parent b1ad8633
Pipeline #3021 failed with stages
from django.db import models
from django.urls import reverse
from django.core.validators import MaxValueValidator, MinValueValidator
import datetime
......@@ -13,6 +14,9 @@ class Author(models.Model):
def __str__(self):
return '{} {}'.format(self.first_name, self.last_name)
def get_absolute_url(self):
return reverse('bookshelf:author-detail', kwargs={'pk': self.pk})
class Books(models.Model):
title = models.CharField(max_length=255)
......@@ -34,3 +38,6 @@ class Books(models.Model):
def __str__(self):
return '{} ({}) by {}'.format(self.title, self.year_published, self.author)
def get_absolute_url(self):
return reverse('bookshelf:books-detail', kwargs={'pk': self.pk})
{% extends 'base.html' %}
{% load static %}
{% block title %}{{ object }}{% endblock %}
{% block heading %}
<h1>{{ object }}</h1>
{% endblock %}
{% block content %}
<p>{{ object.age }}</p>
<p>{{ object.nationality }}</p>
<p>{{ object.bio }}</p>
<p>Books by {{ object }} I love:</p>
<ul>
{% for book in books %}
{% if book.author == object %}
<li>
<a href="{{ book.get_absolute_url }}">{{ book.title }}</a>
</li>
{% endif %}
{% endfor %}
</ul>
{% endblock %}
{% block footing %}
<a href="{% url 'bookshelf:home' %}">Home</a>
<a href="{% url 'bookshelf:books-list' %}">Books</a>
<a href="{% url 'bookshelf:author-list' %}">Authors</a>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block title %}My Favorite Authors{% endblock %}
{% block heading %}
<h1>Elaiza's Favorite Authors</h1>
{% endblock %}
{% block content %}
<ul>
{% for object in object_list %}
<li>
<a href="{{ object.get_absolute_url }}">{{ object }}</a>
</li>
{% endfor %}
</ul>
{% endblock %}
{% block footing %}
<a href="{% url 'bookshelf:home' %}">Home</a>
<a href="{% url 'bookshelf:books-list' %}">Books</a>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block title %}{{ object.title }}{% endblock %}
{% block heading %}
<h1>{{ object.title }}</h1>
{% endblock %}
{% block content %}
<p><a href="{{ object.author.get_absolute_url }}">{{ object.author }}</a></p>
<p>{{ object.publisher }}</p>
<p>{{ object.year_published }}</p>
<p>{{ object.ISBN }}</p>
<p>{{ object.blurb }}</p>
{% endblock %}
{% block footing %}
<a href="{% url 'bookshelf:home' %}">Home</a>
<a href="{% url 'bookshelf:books-list' %}">Books</a>
<a href="{% url 'bookshelf:author-list' %}">Authors</a>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block title %}My Favorite Books{% endblock %}
{% block heading %}
<h1>Elaiza's Favorite Books</h1>
{% endblock %}
{% block content %}
<ul>
{% for object in object_list %}
<li>
<a href="{{ object.get_absolute_url }}">{{ object.title }}</a>
</li>
{% endfor %}
</ul>
{% endblock %}
{% block footing %}
<a href="{% url 'bookshelf:home' %}">Home</a>
<a href="{% url 'bookshelf:author-list' %}">Authors</a>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block title %}My Favorite Books and Authors{% endblock %}
{% block heading %}
<h1>Welcome to Elaiza's Database of Favorite Books and Authors!</h1>
{% endblock %}
{% block content %}
<p>
Elaiza's Database of Favorite Books and Authors consists
of a wide variety of books that interests her the most. The genres
of these books ranges from dark themes such as crime, thriller, and mystery
to heavy themes like drama, romance and more!
</p>
{% endblock %}
{% block footing %}
<a href="{% url 'bookshelf:books-list' %}">Books</a>
<a href="{% url 'bookshelf:author-list' %}">Authors</a>
{% endblock %}
\ No newline at end of file
from django.urls import path
from .views import index
from .views import (index, homepage,
BooksListView, BooksDetailView,
AuthorListView, AuthorDetailView
)
urlpatterns = [
path('', index, name='index'),
path('home', homepage, name='home'),
path('books', BooksListView.as_view(), name='books-list'),
path('books/<int:pk>/details', BooksDetailView.as_view(), name='books-detail'),
path('authors', AuthorListView.as_view(), name='author-list'),
path('authors/<int:pk>/details',
AuthorDetailView.as_view(), name='author-detail'),
]
app_name = "bookshelf"
from django.shortcuts import render
from django.http import HttpResponse
from django.views import View
from django.views.generic.list import ListView
from django.views.generic.detail import DetailView
from .models import Author, Books
def index(request):
return HttpResponse('')
def homepage(request):
return render(request, 'bookshelf/home.html')
class BooksListView(ListView):
model = Books
template_name = 'bookshelf/books.html'
class BooksDetailView(DetailView):
model = Books
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 get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['books'] = Books.objects.all()
return context
......@@ -59,7 +59,7 @@ ROOT_URLCONF = 'elaizabolislis_reading.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'DIRS': [os.path.join(BASE_DIR, 'templates')],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
......@@ -123,6 +123,7 @@ USE_TZ = True
# https://docs.djangoproject.com/en/3.2/howto/static-files/
STATIC_URL = '/static/'
STATICFILES_DIRS = [os.path.join(BASE_DIR, 'static')]
# Default primary key field type
# https://docs.djangoproject.com/en/3.2/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('', include('bookshelf.urls', namespace="bookshelf")),
path('admin/', admin.site.urls),
]
<!DOCTYPE html>
<html lang="">
<head>
<link rel="stylesheet" href="style.css">
<title>{% block title %}{% endblock %}</title>
</head>
<body>
<div id="heading">
{% block heading %}{% endblock %}
</div>
<div id="content">
{% block content %}{% endblock %}
</div>
<div id="footing">
{% block footing %}{% 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