Books Details and Authors details have been added

parent ff663f4b
# Generated by Django 3.2 on 2023-03-29 15:32
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('bookshelf', '0001_initial'),
]
operations = [
migrations.AlterField(
model_name='books',
name='author',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='bookshelf.author'),
),
]
...@@ -19,7 +19,7 @@ class Books(models.Model): ...@@ -19,7 +19,7 @@ class Books(models.Model):
title = models.CharField(max_length=1000) title = models.CharField(max_length=1000)
author = models.ForeignKey( author = models.ForeignKey(
Author, Author,
on_delete=models.PROTECT on_delete=models.CASCADE
) )
publisher = models.CharField(max_length=1000) publisher = models.CharField(max_length=1000)
year_published = models.IntegerField() year_published = models.IntegerField()
......
...@@ -11,4 +11,5 @@ ...@@ -11,4 +11,5 @@
</li> </li>
{% endfor %} {% endfor %}
</ul> </ul>
{% endblock %} <p><a href="http://127.0.0.1:8000/bookshelf/home">Home</a> <a href="http://127.0.0.1:8000/bookshelf/books">Books</a> </p>
\ No newline at end of file {% endblock %}
\ No newline at end of file
{% extends 'base.html' %} {% extends 'base.html' %}
{% load static %} {% load static %}
{% block title %} {{ object.first_name }}{% endblock %} {% block title %} {{ author.first_name }}{% endblock %}
{% block content %} {% block content %}
<h1>{{ object.first_name }} {{object.last_name}}</h1> <h1>{{ author.first_name }} {{author.last_name}}</h1>
<ul> <ul>
<li>{{ object.age }}</li> <li>{{ author.age }}</li>
<li>{{ object.nationality }}</li> <li>{{ author.nationality }}</li>
<li>{{ object.bio }}</li> <li>{{ author.bio }}</li>
</ul> </ul>
<p>
<a href="http://127.0.0.1:8000/bookshelf/home">Home</a>
<a href="http://127.0.0.1:8000/bookshelf/books">Books</a>
<a href="http://127.0.0.1:8000/bookshelf/authors">Authors</a>
</p>
{% endblock %} {% endblock %}
\ No newline at end of file
...@@ -5,10 +5,15 @@ ...@@ -5,10 +5,15 @@
{% block content %} {% block content %}
<h1>{{ object.title }}</h1> <h1>{{ object.title }}</h1>
<ul> <ul>
<li>{{ object.author }}</li> <li>Author: <a href="{{ object.author.get_absolute_url }}""> {{ object.author }}</a></li>
<li>{{ object.publisher }}</li> <li>Publisher: {{ object.publisher }}</li>
<li>{{ object.year_published }}</li> <li>Year Published: {{ object.year_published }}</li>
<li>{{ object.ISBN }}</li> <li>ISBN: {{ object.ISBN }}</li>
<li>{{ object.blurb }}</li> <li>Blurb: {{ object.blurb }}</li>
</ul> </ul>
<p>
<a href="http://127.0.0.1:8000/bookshelf/home">Home</a>
<a href="http://127.0.0.1:8000/bookshelf/books">Books</a>
<a href="http://127.0.0.1:8000/bookshelf/authors">Authors</a>
</p>
{% endblock %} {% endblock %}
\ No newline at end of file
...@@ -11,4 +11,5 @@ ...@@ -11,4 +11,5 @@
</li> </li>
{% endfor %} {% endfor %}
</ul> </ul>
<p><a href="http://127.0.0.1:8000/bookshelf/home">Home</a> <a href="http://127.0.0.1:8000/bookshelf/authors">Authors</a> </p>
{% endblock %} {% endblock %}
\ No newline at end of file
...@@ -10,5 +10,5 @@ ...@@ -10,5 +10,5 @@
<br>that appeals to me. <br>that appeals to me.
</p> </p>
<br> <br>
<a href="http://127.0.0.1:8000/bookshelf/books">Books</a> <p><a href="http://127.0.0.1:8000/bookshelf/books">Books</a> <a href="http://127.0.0.1:8000/bookshelf/authors">Authors</a> </p>
{% endblock %} {% endblock %}
\ No newline at end of file
...@@ -17,7 +17,8 @@ class AuthorsListView(ListView): ...@@ -17,7 +17,8 @@ class AuthorsListView(ListView):
}) })
class AuthorsDetailView(DetailView): class AuthorsDetailView(DetailView):
models = Author model = Author
template_name = 'bookshelf/authors_details.html'
class BooksListView(ListView): class BooksListView(ListView):
def get(self, request): def get(self, request):
...@@ -27,4 +28,6 @@ class BooksListView(ListView): ...@@ -27,4 +28,6 @@ class BooksListView(ListView):
}) })
class BooksDetailView(DetailView): class BooksDetailView(DetailView):
models = Books model = Books
\ No newline at end of file template_name = 'bookshelf/book_details.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