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): ...@@ -15,18 +15,9 @@ class AuthorAdmin(admin.ModelAdmin):
inlines = [BookInline] inlines = [BookInline]
class BookAdmin(admin.ModelAdmin): class BookAdmin(admin.ModelAdmin):
list_display = ("title", "get_author", "year_published", "ISBN") list_display = ("title", "author", "year_published", "ISBN")
list_filter = ("year_published", "publisher",) list_filter = ("author", "publisher",)
search_fields = ("title", "author", "blurb")
# 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"
admin.site.register(Author, AuthorAdmin) admin.site.register(Author, AuthorAdmin)
admin.site.register(Book, BookAdmin) admin.site.register(Book, BookAdmin)
\ No newline at end of file
...@@ -14,6 +14,9 @@ class Author (models.Model): ...@@ -14,6 +14,9 @@ class Author (models.Model):
def __str__(self): def __str__(self):
return self.first_name + " " + self.last_name return self.first_name + " " + self.last_name
def get_absolute_url(self):
return(reverse('authordetail', kwargs={'pk' : self.pk}))
class Book (models.Model): class Book (models.Model):
title = models.CharField(max_length = 50) title = models.CharField(max_length = 50)
author = models.ForeignKey(Author, on_delete = models.CASCADE) author = models.ForeignKey(Author, on_delete = models.CASCADE)
...@@ -23,3 +26,6 @@ class Book (models.Model): ...@@ -23,3 +26,6 @@ class Book (models.Model):
ISBN = models.IntegerField() ISBN = models.IntegerField()
blurb = models.TextField(max_length = 200) 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 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. # 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/ ...@@ -11,6 +11,9 @@ https://docs.djangoproject.com/en/3.2/ref/settings/
""" """
from pathlib import Path 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'. # Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent BASE_DIR = Path(__file__).resolve().parent.parent
...@@ -55,7 +58,7 @@ ROOT_URLCONF = 'javing_reading.urls' ...@@ -55,7 +58,7 @@ ROOT_URLCONF = 'javing_reading.urls'
TEMPLATES = [ TEMPLATES = [
{ {
'BACKEND': 'django.template.backends.django.DjangoTemplates', 'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [], 'DIRS': [os.path.join(BASE_DIR, 'templates')],
'APP_DIRS': True, 'APP_DIRS': True,
'OPTIONS': { 'OPTIONS': {
'context_processors': [ 'context_processors': [
......
...@@ -14,8 +14,9 @@ Including another URLconf ...@@ -14,8 +14,9 @@ Including another URLconf
2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) 2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
""" """
from django.contrib import admin from django.contrib import admin
from django.urls import path from django.urls import path, include
urlpatterns = [ urlpatterns = [
path('admin/', admin.site.urls), 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