Commit 6d916cf2 authored by KaoruSawade's avatar KaoruSawade

Created author_list and author_detail templates, and edited models.py to...

Created author_list and author_detail templates, and edited models.py to implement get_absolute_url on both Author and Books models
parent a0d2cbfa
from django.db import models
from django.urls import reverse
class Author(models.Model):
first_name = models.CharField(max_length=300, default="")
......@@ -9,7 +10,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', args=[self.pk])
class Books(models.Model):
title = models.CharField(max_length=300, default="")
author = models.ForeignKey(Author, on_delete=models.CASCADE)
......@@ -20,3 +23,6 @@ class Books(models.Model):
def __str__(self):
return "\'{}\' by {}, {}".format(self.title, self.author.last_name, self.author.first_name)
def get_absolute_url(self):
return reverse('bookshelf:books-detail', args=[str(self.pk)])
{% extends 'base.html' %}
{% load static %}
{% block title %}{{ author.first_name }} {{ author.last_name }}{% endblock %}
{% block content %}
<h2>{{ author.first_name }} {{ author.last_name }}</h2>
<p>{{ author.age }}</p>
<p>{{ author.nationality }}</p>
<p>{{ author.bio }}</p>
<h3>Books by {{ author.first_name }} {{ author.last_name }} I love:
<ul>
{%for book in book_list%}
<li>{{ book.title }}</li>
{% endfor %}
</ul>
{% endblock %}
{% block navbar %}
<ul class="navbarList">
<li class="navbarItem"><a href="/home">Home</a></li>
<li class="navbarItem"><a href="/books">Books</a></li>
</ul>
{% endblock %}
{% extends 'base.html' %}
{% load static %}
{% block title %}My Favorite Authors{% endblock %}
{% block content %}
<h2>{{name}}'s Database of Favorite Books and Authors:</h2>
<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 navbar %}
<ul class="navbarList">
<li class="navbarItem"><a href="/home">Home</a></li>
<li class="navbarItem"><a href="/books">Books</a></li>
</ul>
{% endblock %}
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