Commit e1756b3a authored by Ciella's avatar Ciella

Created templates, urls, and views for bookshelf app

parent 8e770a65
Pipeline #3066 failed with stages
from django.db import models
from django.urls import reverse
# Create your models here.
class Author(models.Model):
first_name = models.CharField(max_length=255)
last_name = models.CharField(max_length=255)
......@@ -11,14 +11,20 @@ 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 Books(models.Model):
title = models.CharField(max_length=255)
author = models.ForeignKey(Author, on_delete=models.CASCADE)
author = models.ForeignKey(Author, on_delete=models.CASCADE, related_name='books_published')
publisher = models.CharField(max_length=255)
year_published = models.PositiveIntegerField()
ISBN = models.PositiveBigIntegerField()
blurb = models.TextField(max_length=700)
def __str__(self):
return '{}'.format(self.title)
\ No newline at end of file
return '{}'.format(self.title)
def get_absolute_url(self):
return reverse('bookshelf:book_details', kwargs={'pk': self.pk})
\ No newline at end of file
{% extends "base.html" %}
{% block title %}{{ object }}{% endblock %}
{% block header %}{{ object }}{% 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 object.books_published.all %}
<li>
<a href="{{ book.get_absolute_url }}">{{ book }}</a>
</li>
{% endfor %}
</ul>
{% endblock %}
{% block links %}
<a href="/bookshelf/home/">Home</a>&nbsp; &nbsp; &nbsp; &nbsp;
<a href="/bookshelf/books/">Books</a>&nbsp; &nbsp; &nbsp; &nbsp;
<a href="/bookshelf/authors/">Authors</a>
{% endblock %}
\ No newline at end of file
{% extends "base.html" %}
{% block title %}My Favorite Authors{% endblock %}
{% block header %}Ciella's Favorite Authors:{% endblock %}
{% block content %}
<ul>
{% for author in object_list %}
<li>
<a href="{{ author.get_absolute_url }}">{{ author }}</a>
</li>
{% endfor %}
</ul>
{% endblock %}
{% block links %}
<a href="/bookshelf/home/">Home</a>&nbsp; &nbsp; &nbsp; &nbsp;
<a href="/bookshelf/books/">Books</a>
{% endblock %}
\ No newline at end of file
{% extends "base.html" %}
{% block title %}{{ object }}{% endblock %}
{% block header %}{{ object }}{% 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 links %}
<a href="/bookshelf/home/">Home</a>&nbsp; &nbsp; &nbsp; &nbsp;
<a href="/bookshelf/books/">Books</a>&nbsp; &nbsp; &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 header %}Ciella's Favorite Books{% endblock %}
{% block content %}
<ul>
{% for book in object_list %}
<li>
<a href="{{ book.get_absolute_url }}">{{ book }}</a>
</li>
{% endfor %}
</ul>
{% endblock %}
{% block links %}
<a href="/bookshelf/home/">Home</a>&nbsp; &nbsp; &nbsp; &nbsp;
<a href="/bookshelf/authors/">Authors</a>
{% endblock %}
\ No newline at end of file
{% extends "base.html" %}
{% block title %}My Favorite Books & Authors{% endblock %}
{% block header %}Welcome to Ciella's Database of Favorite Books and Authors!{% endblock %}
{% block content %}
Lately, I've been into poetry books, both classical and contemporary. Though before, I've been keen on reading fantasy fiction. I really, really love Soman Chainani and Sylvia Plath!
{% endblock %}
{% block links %}
<a href="/bookshelf/books/">Books</a>&nbsp; &nbsp; &nbsp; &nbsp;
<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 home_view, BooksDetailView, BooksListView, AuthorDetailView, AuthorListView
urlpatterns = [
path('', index, name='index')
path('home/', home_view, name='home_view'),
path('books/', BooksListView.as_view(), name='books_list'),
path('books/<int:pk>/details/', BooksDetailView.as_view(), name='book_details'),
path('authors/', AuthorListView.as_view(), name='author_list'),
path('authors/<int:pk>/details/', AuthorDetailView.as_view(), name='author_details'),
]
app_name = 'bookshelf'
\ No newline at end of file
from django.shortcuts import render
from django.http import HttpResponse
from django.views.generic.detail import DetailView
from django.views.generic.list import ListView
# Create your views here.
def index(request):
return HttpResponse('Hello World!')
\ No newline at end of file
from .models import Author, Books
def home_view(request):
return render(request, 'bookshelf/home.html')
class AuthorDetailView(DetailView):
model = Author
template_name = 'bookshelf/author_details.html'
class AuthorListView(ListView):
model = Author
template_name = 'bookshelf/authors.html'
class BooksDetailView(DetailView):
model = Books
template_name = 'bookshelf/book_details.html'
class BooksListView(ListView):
model = Books
template_name = 'bookshelf/books.html'
\ No newline at end of file
......@@ -59,7 +59,7 @@ ROOT_URLCONF = 'ciellafrancisco_reading.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'DIRS': [os.path.join(BASE_DIR, 'templates')],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
......
{% load static %}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>
{% block title %}{% endblock %}
</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.3/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<h1 class="text-center">{% block header%}{% endblock %}</h1>
<p class="text-center">{% block content %}{% endblock %}</p>
<p class="text-center">{% block links %}{% endblock %}</p>
</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