finished homepage

parent 8f051159
from django.contrib import admin from django.contrib import admin
from .models import Author, Books from .models import Author, Book
class AuthorAdmin(admin.ModelAdmin): class AuthorAdmin(admin.ModelAdmin):
model = Author model = Author
list_display = ('first_name', 'last_name', 'age', 'nationality', 'bio') list_display = ('first_name', 'last_name', 'age', 'nationality', 'bio')
class BooksAdmin(admin.ModelAdmin): class BooksAdmin(admin.ModelAdmin):
model = Books model = Book
list_display = ('title', 'author', 'publisher', 'year_published', 'ISBN', 'blurb') list_display = ('title', 'author', 'publisher', 'year_published', 'ISBN', 'blurb')
# registering the model and the admin is what tells # registering the model and the admin is what tells
# Django that admin pages must be generated for the models specified # Django that admin pages must be generated for the models specified
admin.site.register(Author, AuthorAdmin) admin.site.register(Author, AuthorAdmin)
admin.site.register(Books, BooksAdmin) admin.site.register(Book, BooksAdmin)
\ No newline at end of file \ No newline at end of file
...@@ -15,10 +15,10 @@ class Author(models.Model): ...@@ -15,10 +15,10 @@ class Author(models.Model):
return '{} {}'.format(self.first_name, self.last_name) return '{} {}'.format(self.first_name, self.last_name)
def get_absolute_url(self): def get_absolute_url(self):
return reverse('location_detail', args=[str(self.first_name)]) return reverse('author-detail', kwargs={'pk': self.pk})
class Books(models.Model): class Book(models.Model):
title = models.CharField(max_length=200, default='') title = models.CharField(max_length=200, default='')
author = models.ForeignKey( author = models.ForeignKey(
Author, Author,
...@@ -38,5 +38,5 @@ class Books(models.Model): ...@@ -38,5 +38,5 @@ class Books(models.Model):
return '{} by {}'.format(self.title, self.author) return '{} by {}'.format(self.title, self.author)
def get_absolute_url(self): def get_absolute_url(self):
return reverse('location_detail', args=[str(self.title)]) return reverse('book-detail', kwargs={'pk': self.pk})
{% extends 'base.html' %}
{% block title %}My Favorite Authors{% endblock %}
{% block heading %}
Chris's Favorite Authors:
{% endblock %}
{%block hyperlinks%}
<ul>
{% for i in author_list %}
<li><a href="url">{{i.first_name}} {{i.last_name}}</a></li>
{% endfor %}
<br></br>
<a href="/home">Home</a>
<a href="/books">Books</a>
</ul>
{%endblock%}
\ No newline at end of file
{% extends 'base.html' %}
{% block title %}{{book_list.}}{% endblock %}
{% block heading %}
Chris's Favorite Books:
{% endblock %}
{%block hyperlinks%}
<ul>
{% for i in book_list %}
<li><a href="url">{{i.title}}</a></li>
{% endfor %}
<br></br>
<a href="/home">Home</a>
<a href="/authors">Authors</a>
</ul>
{%endblock%}
\ No newline at end of file
{% extends 'base.html' %}
{% block title %}My Favorite Books{% endblock %}
{% block heading %}
Chris's Favorite Books:
{% endblock %}
{%block hyperlinks%}
<ul>
{% for i in book_list %}
<li><a href="/{{book_list.get_absolute_url}}/details">{{i.title}}</a></li>
{% endfor %}
<br></br>
<a href="/home">Home</a>
<a href="/authors">Authors</a>
</ul>
{%endblock%}
\ No newline at end of file
{% extends 'base.html' %}
{% block style %}
h1 {text-align: center;}
p {text-align: center;}
div {text-align: center;}
{% endblock %}
{% block title %}My Favorite Books and Authors{% endblock %}
{% block heading %}
Welcome to Chris's Database of Favorite Books and Authors!
{% endblock %}
{% block text %}
I enjoy a plethora of genres. as long as the author imerses me in their world, that's an A+ for me!
{% endblock %}
{%block hyperlinks%}
<a href="/books">Books</a>
<a href="/authors">Authors</a>
{%endblock%}
\ No newline at end of file
from django.urls import path from django.urls import path
from .views import index from .views import home_view, BooksListView, AuthorsListView, BookDetailsView, AuthorDetailsView
urlpatterns = [ urlpatterns = [
path('', index, name='index'), path('', home_view, name="My Favorite Books & Authors"),
path('home/', home_view, name="My Favorite Books & Authors"),
path('books/', BooksListView.as_view(), name ="books-list"),
path('books/<int:pk>/details/', BookDetailsView.as_view(), name ="book-item"),
path('authors/', AuthorsListView.as_view(), name ="My Favorite Authors"),
] ]
app_name = "bookshelf" app_name = "bookshelf"
\ 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, Books from django.views import View
from django.views.generic.list import ListView, DetailView
from .models import Author, Book
# Create your views here. # Create your views here.
def index(request): def home_view(request):
return HttpResponse('Hello World! This came from the index view') return render(request, 'bookshelf/home.html', {})
\ No newline at end of file
class BooksListView(ListView):
model = Book
# def get(self, request):
# book_list = Book.objects.all().values
# return render(request, 'bookshelf/books.html', {'book_list': book_list})
class AuthorsListView(ListView):
def get(self, request):
author_list = Author.objects.all().values
return render(request, 'bookshelf/authors.html', {'author_list': author_list})
class BookDetailsView(DetailView):
model = Book
class AuthorDetailsView(DetailView):
model = Author
\ No newline at end of file
...@@ -19,7 +19,6 @@ load_dotenv() ...@@ -19,7 +19,6 @@ 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
# Quick-start development settings - unsuitable for production # Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/4.1/howto/deployment/checklist/ # See https://docs.djangoproject.com/en/4.1/howto/deployment/checklist/
...@@ -59,7 +58,7 @@ ROOT_URLCONF = 'chrisolivares_reading.urls' ...@@ -59,7 +58,7 @@ ROOT_URLCONF = 'chrisolivares_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': [
......
"""chrisolivares_reading URL Configuration
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/4.1/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: path('', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.urls import include, path
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, include from django.urls import path, include
urlpatterns = [ urlpatterns = [
path('bookshelf/', include('bookshelf.urls', namespace='bookshelf')), path('', include("bookshelf.urls")),
path('admin/', admin.site.urls), path('admin/', admin.site.urls),
] ]
<!DOCTYPE html>
<html lang="en">
<style>{% block style %}{% endblock %}</style>
<head>
<title>{% block title %}{% endblock %}</title>
</head>
<body>
<div id="heading">
<h1>{% block heading %}{% endblock %}</h1>
</div>
<div id="text">
{% block text %}{% endblock %}
</div>
<div id="hyperlinks">
{% block hyperlinks %}{% endblock %}
</div>
</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