Commit 3ed479e2 authored by Ysobel Vera's avatar Ysobel Vera

Created and edited html files in templates, and edited views and models in the bookshelf app

+ Created and edited the authors, books, author_details, and book_details html files according to the lab specifications.
+edited the models to have get_absolute_url to configure urls to Books and Author
+edited the views to contain the Function based view for home.html and the class based views for the authors, books, author_details, and book_details html files
+these were done to configure urls and to connect the models and views
parent 2ad2240f
Pipeline #3064 failed with stages
......@@ -11,16 +11,22 @@ class Author(models.Model):
def __str__(self):
return '{} {}'.format(self.first_name, self.last_name)
def get_absolute_url(self):
return f"{self.pk}"
class Books(models.Model):
title = models.CharField(max_length=100)
author = models.ForeignKey(Author, on_delete=models.CASCADE)
author = models.ForeignKey(Author, on_delete=models.CASCADE, related_name = "books")
publisher = models.CharField(max_length=100)
year_published = models.IntegerField()
ISBN = models.IntegerField()
blurb = models.TextField(max_length=1200)
def __str__(self):
return '{} ({}) by {}'.format(self.title, self.year_published, self.author)
return '{} ({}) {}'.format(self.title, self.year_published, self.author)
def get_absolute_url(self):
return f"{self.pk}"
<!DOCTYPE html>
<html lang="en">
<!--
<head>
<link rel="stylesheet" href="style.css">
<title>{% block title %}My amazing site{% endblock %}</title>
<title>{% block title %}{% endblock %}</title>
{% block styles %}{% endblock %}
</head>
<body>
......@@ -12,5 +11,4 @@
</div>
{% block scripts %}{% endblock %}
</body>
-->
</html>
\ No newline at end of file
{% extends 'base.html' %}
{% block title %}{{ object.first_name }} {{ object.last_name }}{% endblock %}
{% block content %}
<h1>{{ object.first_name }} {{ object.last_name }}</h1>
<div>
<p>Age: {{ object.age }}<br>
Nationality: {{ object.nationality }}<br>
Bio: {{ object.bio }}</p>
</div>
<div>
<h2>Books by {{ object.first_name }} {{ object.last_name }} I love: </h2>
{% for book in object.books.all %}
<li>
<a href="/books/{{ book.get_absolute_url }}/details/"> {{ book.title }}</a>
</li>
{% endfor %}
<br><br>
<a href="/home">Home</a>
<a href="/books">Books</a>
</div>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% block title %}My Favorite Authors{% endblock %}
{% block content %}
<h1>Yso’s Favorite Authors:</h1>
<ul>
{% for object in object_list %}
<li>
<a href="{{ object.get_absolute_url }}/details/">
{{ object.first_name }} {{ object.last_name }}
</a>
</li>
{% endfor %}
</ul>
<div>
<a href="/home">Home</a>
<a href="/books">Books</a>
</div>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% block title %}{{ object.title }}{% endblock %}
{% block content %}
<h1>{{ object.title }}</h1>
<div>
<p>Author: <a href="/authors/{{ object.author.get_absolute_url }}/details/">{{ object.author }}</a><br>
Publisher: {{ object.publisher }}<br>
Year Published: {{ object.year_published }}<br>
ISBN: {{ object.ISBN }}<br>
Blurb: {{ object.blurb }}<br></p>
<br><br>
<a href="/home">Home</a>
<a href="/books">Books</a>
<a href="/authors">Authors</a>
</div>
{% endblock %}
\ No newline at end of file
{% comment %}
{% extends 'base.html' %}
{% load static %}
{% block title %}My Favorite Books{% endblock %}
{% block body %}
{% block content %}
<h1>Yso’s Favorite Books:</h1>
<ul>
{% for book in Books.objects.all() %}
{% for object in object_list %}
<li>
<a href="{{ book.get_absolute_url }}">
{{ book.title }}
<a href="{{ object.get_absolute_url }}/details/">
{{ object.title }}
</a>
</li>
{% endfor %}
</ul>
<div>
<a href="/home">Home</a>
<a href="/authors">Authors</a>
</div>
{% endblock %}
{% endcomment %}
\ No newline at end of file
{% comment %}
{% extends 'base.html' %}
{% load static %}
{% block title %}My Favorite Books & Authors{% endblock %}
{% block content %}
<h1>Welcome to Yso’s Database of Favorite Books and Authors</h1>
<p>Reading is one of my favorite hobbies to do in my free time. I especially love fantasy, historical fiction, <br>mystery, and coming-of-age books that deal with many characters and their relationships to one another. The <br> authors that appeal to me tend to have a dialogue-heavy writing style or at least do not make descriptions and <br>exposition the main focus of the writing. I like authors that are able to convey situations and relationships <br>through the characters’ actions and dialogue without having to tell readers what to think, rather there is focus <br>on showing readers what happens. </p>
<p>Reading is one of my favorite hobbies to do in my free time. I especially love fantasy, historical fiction, <br>mystery, and coming-of-age books that deal with many characters and their relationships to one another. The <br> authors that appeal to me tend to have a dialogue-heavy writing style or at least do not make descriptions and <br>exposition the main focus of the writing. I like authors that are able to convey situations and relationships <br>through the characters’ actions and dialogue without having to tell readers what to think, rather there is focus <br>on showing readers what happens. <br><br></p>
<div>
<a href="/books">Books</a>
<a href="/authors">Authors</a>
</div>
{% endblock %}
{% endcomment %}
from django.urls import path
from .views import index
from .views import home_view, BooksDetailView, BooksView, AuthorsView, AuthorDetailsView
urlpatterns = [
path('', index, name='index'),
path('home/', home_view, name='index'),
path('books/', BooksView.as_view(), name='books'),
path('books/<int:pk>/details/', BooksDetailView.as_view(), name='books-detail'),
path('authors/', AuthorsView.as_view(), name='authors'),
path('authors/<int:pk>/details/', AuthorDetailsView.as_view(), name='author-detail'),
]
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.detail import DetailView
from django.views.generic.list import ListView
from .models import Books, Author
def index(request):
return HttpResponse('Hello World! This came from the index view')
def home_view(request):
return render(request, 'home.html')
class BooksDetailView(DetailView):
model = Books
template_name = "bookshelf/book_detais.html"
class BooksView(ListView):
model = Books
template_name = "bookshelf/books.html"
class AuthorsView(ListView):
model = Author
template_name = "bookshelf/authors.html"
class AuthorDetailsView(DetailView):
model = Author
template_name = "bookshelf/author_details.html"
\ No newline at end of file
......@@ -59,7 +59,7 @@ ROOT_URLCONF = 'ysovera_reading.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'DIRS': [os.path.join(BASE_DIR, 'templates')],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
......
......@@ -16,6 +16,7 @@ Including another URLconf
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('bookshelf.urls', namespace='bookshelf')),
......
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