Commit 55f66043 authored by Almira Redoble's avatar Almira Redoble

Created working views and templates for author-detail and book-detail.

parent 162c3d21
from django.db import models
from django.core.validators import MinValueValidator, MaxValueValidator
from django.urls import reverse
import datetime
class Author(models.Model):
......@@ -12,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-details', kwargs={'pk': self.pk})
class Books(models.Model):
title = models.CharField(max_length=255, default='')
author = models.ForeignKey(
......@@ -36,3 +41,6 @@ class Books(models.Model):
def __str__(self):
return '{} by {}, {}'.format(self.title, self.author,
self.year_published)
def get_absolute_url(self):
return reverse('bookshelf:book-details', kwargs={'pk': self.pk})
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block title %}
{{ object }}
{% endblock %}
{% block heading %}
{{ object }}
{% endblock %}
{% block content %}
<ul class="no-bullets">
<li>
<a href="{{ object.author.get_absolute_url }}">{{ object.author }}</a>
</li>
<li>
{{ object.age }}
</li>
<li>
{{ object.nationality }}
</li>
<li>
{{ object.bio }}
</li>
</ul>
<h2>Books by {{ object }} I love:</h2>
<ul>
{% for book in object.books.all %}
<li>
<a href="{{ book.get_absolute_url }}">{{ book.title }}</a>
</li>
{% endfor %}
</ul>
{% endblock %}
{% block footer %}
<a href="{% url 'bookshelf:home' %}">Home</a>
<a href="{% url 'bookshelf:books' %}">Books</a>
<a href="{% url 'bookshelf:authors' %}">Authors</a>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block header %}
<title>My Favorite Authors</title>
{% block title %}
My Favorite Authors
{% endblock %}
{% block heading %}
......
{% extends 'base.html' %}
{% load static %}
{% block title %}
{{ object.title }}
{% endblock %}
{% block heading %}
{{ object.title }}
{% endblock %}
{% block content %}
<ul class="no-bullets">
<li>
<a href="{{ object.author.get_absolute_url }}">{{ object.author }}</a>
</li>
<li>
{{ object.publisher }}
</li>
<li>
{{ object.year_published }}
</li>
<li>
{{ object.ISBN }}
</li>
<li>
{{ object.blurb }}
</li>
</ul>
{% endblock %}
{% block footer %}
<a href="{% url 'bookshelf:home' %}">Home</a>
<a href="{% url 'bookshelf:books' %}">Books</a>
<a href="{% url 'bookshelf:authors' %}">Authors</a>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block header %}
<title>My Favorite Books</title>
{% block title %}
My Favorite Books
{% endblock %}
{% block heading %}
......
{% extends 'base.html' %}
{% load static %}
{% block header %}
<title>{{ header }}</title>
{% block title %}
{{ title }}
{% endblock %}
{% block heading %}
......
......@@ -8,7 +8,8 @@ urlpatterns = [
path('home/', HomePageView, name='home'),
path('books/', BookListView.as_view(), name='books'),
path('authors/', AuthorListView.as_view(), name='authors'),
path('books/<int:pk>/details', BookDetailView.as_view(), name='book-details'),
path('authors/<int:pk>/details', AuthorDetailView.as_view(), name='author-details')
]
app_name = "bookshelf"
\ No newline at end of file
......@@ -13,7 +13,7 @@ def HomePageView(request):
"books I've read are classics, born out of a need to know what most " \
"people already know. "
return render(request, 'bookshelf/home.html', {
'header': title,
'title': title,
'heading': heading,
'content': content,
})
......@@ -24,6 +24,7 @@ class BookListView(ListView):
class BookDetailView(DetailView):
model = Books
template_name = 'bookshelf/book_details.html'
class AuthorListView(ListView):
model = Author
......@@ -31,3 +32,4 @@ class AuthorListView(ListView):
class AuthorDetailView(DetailView):
model = Author
template_name = 'bookshelf/author_details.html'
ul.no-bullets {
list-style-type: none;
}
#heading {
}
#content {
}
#footer {
}
\ No newline at end of file
......@@ -2,10 +2,8 @@
<html lang="en">
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="style.css">
<div id="header">
{% block header %}{% endblock %}
</div>
<link rel="stylesheet" href="/static/style.css">
<title>{% block title %}{% endblock %}</title>
</head>
<body>
<div id="heading">
......
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