Fixed links in all html files and fixed views.

parent 2c1ca603
# Default ignored files
/shelf/
/workspace.xml
<component name="InspectionProjectProfileManager">
<settings>
<option name="USE_PROJECT_PROFILE" value="false" />
<version value="1.0" />
</settings>
</component>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
<component name="PyDocumentationSettings">
<option name="format" value="PLAIN" />
<option name="myDocStringFormat" value="Plain" />
</component>
</module>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.11" project-jdk-type="Python SDK" />
<component name="PyCharmProfessionalAdvertiser">
<option name="shown" value="true" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/je_siongco_reading.iml" filepath="$PROJECT_DIR$/.idea/je_siongco_reading.iml" />
</modules>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
</component>
</project>
\ No newline at end of file
from django.contrib import admin
from .models import Author, Books
class AuthorAdmin(admin.ModelAdmin):
model = Author
list_display = ('first_name', 'last_name', 'age', 'nationality', 'bio')
class BooksAdmin(admin.ModelAdmin):
model = Books
list_display = ('title', 'author')
admin.site.register(Author, AuthorAdmin)
admin.site.register(Books, BooksAdmin)
from django.apps import AppConfig
class BookshelfConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'bookshelf'
# Generated by Django 3.2 on 2023-03-27 15:10
import django.core.validators
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='Author',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('first_name', models.CharField(max_length=100)),
('last_name', models.CharField(max_length=50)),
('age', models.IntegerField(validators=[django.core.validators.MaxValueValidator(0), django.core.validators.MinValueValidator(100)])),
('nationality', models.CharField(max_length=50)),
('bio', models.CharField(max_length=700)),
],
),
migrations.CreateModel(
name='Books',
fields=[
('title', models.CharField(max_length=500)),
('publisher', models.CharField(max_length=100)),
('year_published', models.IntegerField()),
('ISBN', models.CharField(max_length=13, primary_key=True, serialize=False, unique=True, validators=[django.core.validators.MinLengthValidator(13), django.core.validators.MaxLengthValidator(13)])),
('blurb', models.CharField(max_length=1000)),
('author', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='bookshelf.author')),
],
),
]
# Generated by Django 3.2 on 2023-03-27 19:09
import django.core.validators
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('bookshelf', '0001_initial'),
]
operations = [
migrations.AlterField(
model_name='author',
name='age',
field=models.IntegerField(validators=[django.core.validators.MaxValueValidator(100), django.core.validators.MinValueValidator(0)]),
),
]
# Generated by Django 3.2 on 2023-03-29 02:44
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('bookshelf', '0002_alter_author_age'),
]
operations = [
migrations.AlterField(
model_name='books',
name='author',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='author', to='bookshelf.author'),
),
]
from django.core.validators import MaxValueValidator, MinValueValidator, MinLengthValidator, MaxLengthValidator
from django.db import models
from django.urls import reverse
class Author(models.Model):
first_name = models.CharField(max_length=100)
last_name = models.CharField(max_length=50)
age = models.IntegerField(validators=[MaxValueValidator(100), MinValueValidator(0)])
nationality = models.CharField(max_length=50)
bio = models.CharField(max_length=700)
def __str__(self):
return '{}, {}'.format(self.last_name, self.first_name)
def get_absolute_url(self):
return reverse('authors-detail', kwargs={'pk': self.pk})
class Books(models.Model):
title = models.CharField(max_length=500)
author = models.ForeignKey(Author, on_delete=models.CASCADE, related_name='books')
publisher = models.CharField(max_length=100)
year_published = models.IntegerField()
ISBN = models.CharField(unique=True, primary_key=True, max_length=13, validators=[MinLengthValidator(13),
MaxLengthValidator(13)])
blurb = models.CharField(max_length=1000)
def get_absolute_url(self):
return reverse('books-detail', kwargs={'pk': self.pk})
from django.test import TestCase
# Create your tests here.
from django.urls import path
from .views import (
BooksListView, BooksDetailView, AuthorsDetailView, AuthorsListView, HomepageView
)
urlpatterns = [
path('books/', BooksListView.as_view(), name='books-list'),
path('books/<int:pk>/details/', BooksDetailView.as_view(), name='books-detail'),
path('authors/', AuthorsListView.as_view(), name='authors-list'),
path('authors/<int:pk>/details/', AuthorsDetailView.as_view(), name='authors-detail'),
path('home/', HomepageView, name='home'),
]
from django.http import HttpResponse
from django.shortcuts import render
from django.template import loader
from django.views.generic.list import ListView
from django.views.generic.detail import DetailView
from .models import Author, Books
def HomepageView(request):
template = loader.get_template("bookshelf/home.html")
return HttpResponse(template.render({}, request))
class BooksListView(ListView):
model = Books
class BooksDetailView(DetailView):
model = Books
class AuthorsListView(ListView):
model = Author
class AuthorsDetailView(DetailView):
model = Author
'''
books = Books.objects.filter(author=Author)
extra_context = {'books': books.author.all()}
def get_context_data(self, **kwargs):
context = super().get_context_data()
books = Books.objects.filter(author=1)
context['books_list'] = books.author.all()
return context
'''
"""
ASGI config for je_siongco_reading project.
It exposes the ASGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/3.2/howto/deployment/asgi/
"""
import os
from django.core.asgi import get_asgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'je_siongco_reading.settings')
application = get_asgi_application()
"""
Django settings for je_siongco_reading project.
Generated by 'django-admin startproject' using Django 3.2.
For more information on this file, see
https://docs.djangoproject.com/en/3.2/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/3.2/ref/settings/
"""
import os
from pathlib import Path
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.2/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure--c-^qcc8g##kwfl3&(s+ecn7-fi@corylqffl!cdpo^e87a)43'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = []
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'bookshelf',
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
ROOT_URLCONF = 'je_siongco_reading.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templates')],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
WSGI_APPLICATION = 'je_siongco_reading.wsgi.application'
# Database
# https://docs.djangoproject.com/en/3.2/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
}
}
# Password validation
# https://docs.djangoproject.com/en/3.2/ref/settings/#auth-password-validators
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]
# Internationalization
# https://docs.djangoproject.com/en/3.2/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.2/howto/static-files/
STATIC_URL = '/static/'
# Default primary key field type
# https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
"""je_siongco_reading URL Configuration
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/3.2/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.urls import include, path
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('bookshelf.urls'))
]
"""
WSGI config for je_siongco_reading project.
It exposes the WSGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/3.2/howto/deployment/wsgi/
"""
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'je_siongco_reading.settings')
application = get_wsgi_application()
#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys
def main():
"""Run administrative tasks."""
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'je_siongco_reading.settings')
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
) from exc
execute_from_command_line(sys.argv)
if __name__ == '__main__':
main()
{% extends 'base.html' %}
{% block title %}
{% endblock %}
{% block content %}
{% block body %}
{% endblock %}
<a href="/home/">Home</a>
<a href="/books/">Books</a>
<a href="/authors/">Authors</a>
{% endblock %}
{% extends 'base.html' %}
{% block title %}
My Favourite Authors
{% endblock %}
{% block content %}
<h1>J.E.'s Favourite Authors:</h1>
{% block body %}
{% endblock %}
<a href="/home/">Home</a>
<a href="/books/">Books</a>
{% endblock %}
<!DOCTYPE html>
<html lang="en">
<head>
<title>{% block title %}{% endblock %}</title>
</head>
<body>
{% block content%} {% endblock %}
</body>
</html>
\ No newline at end of file
{% extends 'base.html' %}
{% block title %}
{% endblock %}
{% block content %}
{% block body %}
{% endblock %}
<a href="/home/">Home</a>
<a href="/books/">Books</a>
<a href="/authors/">Authors</a>
{% endblock %}
{% extends 'base.html' %}
{% block title %}
My Favourite Books
{% endblock %}
{% block content %}
<h1>J.E.'s Favourite Books:</h1>
<ul>
{% block body %}
{% endblock %}
</ul>
{% endblock %}
{% extends 'author_details.html' %}
{% block title %}
{{ object.first_name }} {{ object.last_name }}
{% endblock %}
{% block body %}
<h1>{{ object.first_name }} {{ object.last_name }}</h1>
<p>
{{ object.age }} <br>
{{ object.nationality }} <br>
{{ object.bio }}
</p>
<p>
Books by {{ object.first_name }} {{ object.last_name }} I love: <br>
<ul>
{% for book in object.books.all %}
<li>
<a href="{{book.get_absolute_url}}">{{ book.title }}</a>
</li>
{% endfor %}
</ul>
</p>
{% endblock %}
{% extends 'authors.html' %}
{% block body %}
<ul>
{% for object in object_list %}
<li>
<a href="{{ object.get_absolute_url }}">{{ object.first_name }} {{ object.last_name }}</a>
</li>
{% endfor %}
</ul>
{% endblock %}
{% extends 'book_details.html' %}
{% block title %}
{{ object.title }}
{% endblock %}
{% block body %}
<h1>{{ object.title }}</h1>
<h2><a href="{{ object.author.get_absolute_url }}">
{{ object.author }}
</a></h2>
<h2>{{ object.publisher }}</h2>
<h2>{{ object.year_published }}</h2>
<h2>{{ object.ISBN }}</h2>
<h2>{{ object.blurb }}</h2>
{% endblock %}
{% extends 'books.html' %}
{% block body %}
<ul>
{% for object in object_list %}
<li>
<a href="{{ object.get_absolute_url }}">{{object.title}}</a>
</li>
{% endfor %}
</ul>
{% endblock %}
{% extends 'base.html' %}
{% block title %}
My Favourite Books and Authors
{% endblock %}
{% block content %}
<h1>Welcome to J.E.'s Database of Favourite Books and Authors!</h1>
<hr>
<p>
I do not have a particular genre I lean towards to. Should I choose one, I would have to pick
books with a political theme to it. The books in my database should reflect it in some form or manner.
</p>
<a href="/books/">Books</a>
<a href="/authors/">Authors</a>
{% endblock %}
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