Commit ea8ea2ff authored by Javi Ng's avatar Javi Ng

finished populating, created html templates

parent 9cf58a33
......@@ -15,18 +15,9 @@ class AuthorAdmin(admin.ModelAdmin):
inlines = [BookInline]
class BookAdmin(admin.ModelAdmin):
list_display = ("title", "get_author", "year_published", "ISBN")
list_filter = ("year_published", "publisher",)
# display author name
def get_author(self, obj):
return obj.author
# title of column for get_author
get_author.short_description = "Author"
# sorting by Author
get_author.admin_order_field = "Author"
list_display = ("title", "author", "year_published", "ISBN")
list_filter = ("author", "publisher",)
search_fields = ("title", "author", "blurb")
admin.site.register(Author, AuthorAdmin)
admin.site.register(Book, BookAdmin)
\ No newline at end of file
......@@ -13,6 +13,9 @@ class Author (models.Model):
# when referred to, use firstname lastname
def __str__(self):
return self.first_name + " " + self.last_name
def get_absolute_url(self):
return(reverse('authordetail', kwargs={'pk' : self.pk}))
class Book (models.Model):
title = models.CharField(max_length = 50)
......@@ -22,4 +25,7 @@ class Book (models.Model):
year_published = models.IntegerField(default = 1984)
ISBN = models.IntegerField()
blurb = models.TextField(max_length = 200)
\ No newline at end of file
blurb = models.TextField(max_length = 200)
def get_absolute_url(self):
return(reverse('bookdetail', kwargs={'pk' : self.pk}))
{% extends 'base.html' %}
{% block content %}
<h1>Welcome to Javi's Database of Favorite Books and Authors!</h1>
Admittedly, half of the books are dummy data or jokes and the other half are actual books I've read.
I like to think that the jokes are also reflective of my personality though.
{% endblock %}
\ No newline at end of file
from django.urls import path
from . import views
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"),
]
\ 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
# Create your views here.
def HomeView(request):
return render(request, "bookshelf/home.html")
class BookListView(ListView):
model = Book
class BookDetailView(DetailView):
model = Book
class AuthorListView(ListView):
model = Author
class AuthorDetailView(DetailView):
model = Author
\ No newline at end of file
......@@ -11,6 +11,9 @@ https://docs.djangoproject.com/en/3.2/ref/settings/
"""
from pathlib import Path
import os
from os.path import join, dirname
from dotenv import load_dotenv
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
......@@ -55,7 +58,7 @@ ROOT_URLCONF = 'javing_reading.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'DIRS': [os.path.join(BASE_DIR, 'templates')],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
......
......@@ -14,8 +14,9 @@ Including another URLconf
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path
from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
path('bookshelf/', include('bookshelf.urls'))
]
<html lang="en">
<head>
<link rel="stylesheet" href="style.css">
<title>{% block title %}My Favorite Books and Authors{% endblock %}</title>
{% block styles %}{% endblock %}
</head>
<body>
<div id="content">
{% block content %}{% endblock %}
</div>
{% block scripts %}{% endblock %}
</body>
</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