Commit e95dad78 authored by Stefan Gomez's avatar Stefan Gomez

Created and filled the required templates in accordance with the specs.

parent ff56a4af
Pipeline #3056 failed with stages
from django.db import models
from django.urls import reverse
class Author(models.Model):
......@@ -10,6 +11,10 @@ class Author(models.Model):
def __str__(self):
return '{}, {}'.format(self.last_name, self.first_name)
def get_absolute_url(self):
return reverse('bookshelf:author-detail', kwargs={'pk': self.pk})
class Book(models.Model):
title = models.CharField(max_length=100)
......@@ -23,4 +28,8 @@ class Book(models.Model):
blurb = models.TextField()
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-detail', kwargs={'pk': self.pk})
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block title %} {{ author.first_name }} {{ author.last_name }} {% endblock %}
{% block content %}
<h1>{{ author.first_name }} {{ author.last_name }}</h1>
<h3>{{ author.age }}</h3>
<h3>{{ author.nationality }}</h3>
<h3>{{ author.bio }}</h3>
<br>
<h1> Books by {{ author.first_name }} {{ author.last_name }} I love:</h1>
<ul>
{% for book in author.book_set.all %}
<li>
<a href="{{ book.get_absolute_url }}">{{ book.title }}</a>
</li>
{% endfor %}
</ul>
{% endblock %}
{% block footer %}<a href="/home">Home</a> | <a href="/books">Books</a> | <a href="/authors">Authors</a>{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block title %} My Favorite Authors{% endblock %}
{% block content %}
<h1>Stefan's Favorite Authors:</h1>
<ul>
{% for author in author_list %}
<li>
<a href="{{author.get_absolute_url}}">
{{ author.first_name }} {{ author.last_name }}
</a>
</li>
{% endfor %}
</ul>
{% endblock %}
{% block footer %}<a href="/home">Home</a> | <a href="/books">Books</a>{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block title %} {{ book.title }} {% endblock %}
{% block content %}
<h1>{{ book.title }}</h1>
<h3><a href="{{ book.author.get_absolute_url }}">{{ book.author.first_name }} {{ book.author.last_name }}</a></h3>
<h3>{{ book.publisher }}</h3>
<h3>{{ book.year_published }}</h3>
<h3>{{ book.ISBN }}</h3>
<p>{{ book.blurb }}</p>
{% endblock %}
{% block footer %}<a href="/home">Home</a> | <a href="/books">Books</a> | <a href="/authors">Authors</a>{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block title %} My Favorite Books{% endblock %}
{% block content %}
<h1>Stefan's Favorite Books:</h1>
<ul>
{% for book in book_list %}
<li>
<a href="{{ book.get_absolute_url}}">
{{ book.title }}
</a>
</li>
{% endfor %}
</ul>
{% endblock %}
{% block footer %}<a href="/home">Home</a> | <a href="/authors">Authors</a>{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block title %} My Favorite Books And Authors {% endblock %}
{% block content %}
<p>Welcome to Stefan's Database of Favorite Books and Authors!<br>
<br>
To be honest I am not really a book kind of guy. Why read a book when you can just watch instead you feel me? Nevertheless I do prefer to read fictional fantasy kind of books such as that of mainly the Harry Potter and Percy Jackson books. With that in mind I personally look up to Rick Riordan because J.K Rowling has a bunch of controversies while Rick Riordan just seems like a down to earth kind of guy. </p>
{% endblock %}
{% block footer %}<a href="/books">Books</a> | <a href="/authors">Authors</a>{% endblock %}
\ No newline at end of file
from django.urls import path
from .views import home, BooksView, PerBooksView, AuthorsView, PerAuthorsView
urlpatterns = [
path('home', home, name='home'),
path('books', BooksView.as_view(), name='books'),
path('books/<int:pk>/details', PerBooksView.as_view(), name='book-detail'),
path('authors', AuthorsView.as_view(), name='authors'),
path('authors/<int:pk>/details', PerAuthorsView.as_view(), name='author-detail')
]
app_name = "bookshelf"
\ No newline at end of file
from django.shortcuts import render
from django.views import View
from .models import Author, Book
from django.views.generic.list import ListView
from django.views.generic.detail import DetailView
# Create your views here.
def home(request):
return render(request, 'bookshelf/home.html')
class BooksView(ListView):
model = Book
template_name = 'bookshelf/books.html'
class PerBooksView(DetailView):
model = Book
template_name = 'bookshelf/book_details.html'
class AuthorsView(ListView):
model = Author
template_name = 'bookshelf/authors.html'
class PerAuthorsView(DetailView):
model = Author
template_name = 'bookshelf/author_details.html'
\ No newline at end of file
......@@ -14,8 +14,9 @@ Including another URLconf
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path
from django.urls import path, include
urlpatterns = [
path('', include('bookshelf.urls')),
path('admin/', admin.site.urls),
]
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