Commit aaa111b1 authored by Javi Ng's avatar Javi Ng

wrote template code TODO: navigation bar

parent ea8ea2ff
No preview for this file type
from django.db import models
from django.urls import reverse
# Create your models here.
class Author (models.Model):
......@@ -19,7 +20,7 @@ class Author (models.Model):
class Book (models.Model):
title = models.CharField(max_length = 50)
author = models.ForeignKey(Author, on_delete = models.CASCADE)
author = models.ForeignKey(Author, on_delete = models.CASCADE, related_name = 'booklist')
publisher = models.CharField(max_length = 100)
year_published = models.IntegerField(default = 1984)
......
{% extends 'base.html' %}
{% block title %} {{ object }} {% endblock %}
{% block content %}
<h1>{{ object }}</h1>
<h2>{{ object.age }}</h2>
{{ object.nationalism }} <br>
{{ object.bio }} <br> <br>
Books by {{ object }} I love:
<ul>
{% for book in object.booklist.all %}
<li>
<a href="{{ book.get_absolute_url }}">
{{ book.title }}
</a>
</li>
{% endfor %}
</ul>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% block title %} My Favorite Authors {% endblock %}
{% block content %}
<h1>Javi's Favorite Authors:</h1>
<ul>
{% for author in author_list %}
<li>
<a href="{{ author.get_absolute_url }}">
{{ author }}
</a>
</li>
{% endfor %}
</ul>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% block title %} {{ object.title }} {% endblock %}
{% block content %}
<h1>{{ object.title }}</h1>
<h2>
<a href = {{ object.author.get_absolute_url }}>
{{ object.author }}
</a>
</h2>
{{ object.publisher }} <br>
Published {{ object.year_published}} <br> <br>
ISBN {{ object.ISBN }} <br> <br>
{{ object.blurb }} <br>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% block title %} My Favorite Books {% endblock %}
{% block content %}
<h1>Javi's Favorite Books:</h1>
<ul>
{% for book in book_list %}
<li>
<a href="{{ book.get_absolute_url }}">
{{book.title}}
</a>
</li>
{% endfor %}
</ul>
{% endblock %}
\ No newline at end of file
......@@ -5,6 +5,6 @@ urlpatterns = [
path('home/', views.HomeView, name = "home"),
path('books/', views.BookListView.as_view(), name="booklist"),
path('books/<int:pk>/details', views.BookDetailView.as_view(), name="bookdetail"),
path('authors/', views.BookListView.as_view(), name="authorlist"),
path('authors/<int:pk>/details', views.BookDetailView.as_view(), name="authordetail"),
path('authors/', views.AuthorListView.as_view(), name="authorlist"),
path('authors/<int:pk>/details', views.AuthorDetailView.as_view(), name="authordetail"),
]
\ No newline at end of file
from django.http import HttpResponse
from django.shortcuts import render
from .models import Author, Book
from datetime import date
from django.views import View
from django.views.generic.list import ListView
from django.views.generic.detail import DetailView
......@@ -11,13 +9,17 @@ def HomeView(request):
return render(request, "bookshelf/home.html")
class BookListView(ListView):
template_name = 'bookshelf/books.html'
model = Book
class BookDetailView(DetailView):
template_name = 'bookshelf/book_details.html'
model = Book
class AuthorListView(ListView):
template_name = 'bookshelf/authors.html'
model = Author
class AuthorDetailView(DetailView):
template_name = 'bookshelf/author_details.html'
model = Author
\ 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