Commit 9140a81c authored by Cheska Hung's avatar Cheska Hung

final working verision

parent 9eff115d
Pipeline #3052 canceled with stages
# Generated by Django 4.1.7 on 2023-03-28 13:34
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('bookshelf', '0002_alter_books_isbn'),
]
operations = [
migrations.AlterField(
model_name='books',
name='author',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='books', to='bookshelf.author'),
),
]
......@@ -15,7 +15,7 @@ class Author(models.Model):
class Books(models.Model):
title = models.CharField(max_length=200)
author = models.ForeignKey(Author, on_delete=models.CASCADE)
author = models.ForeignKey(Author, related_name="books", on_delete=models.CASCADE)
publisher = models.CharField(max_length=200)
year_published = models.DateField()
ISBN = models.PositiveIntegerField(
......
......@@ -29,4 +29,6 @@ class AuthorListView(ListView):
class AuthorDetailView(DetailView):
model = Author
queryset = Author.objects.all()
template_name = 'authors_details.html'
context_object_name = 'authors'
No preview for this file type
......@@ -7,7 +7,7 @@
<h1>{{object.first_name}}{{object.last_name}}</h1>
<h2>{{object.age}}</h2>
<h2>{{object.nationality}}</h2>
<h2>{{object.bio}}</h2>
<h2>{{authors.bio}}</h2>
{% for Books in object_list %}
<li>
......@@ -18,6 +18,12 @@
{% endfor %}
<br><br>
<h2>Books by {{object.first_name}}{{object.last_name}} that I love:</h2>
{% for books in authors.books.all %}
<a href="http://127.0.0.1:8000/books/{{ books.pk }}/details">
{{books.title}}
</a>
<br>
{% endfor %}
<br><br>
<a href="/books">Books</a>
<a href="/authors">Authors</a>
......
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