Commit ccb1108d authored by Alec Dayupay's avatar Alec Dayupay

Made and Populated Models. Made and Inherited Templates. Made Views and URLs.

parent ded68071
Pipeline #3025 canceled with stages
......@@ -11,6 +11,7 @@ https://docs.djangoproject.com/en/3.2/ref/settings/
"""
from pathlib import Path
import os
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
......@@ -31,6 +32,7 @@ ALLOWED_HOSTS = []
# Application definition
INSTALLED_APPS = [
'bookshelf.apps.BookshelfConfig',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
......@@ -54,7 +56,7 @@ ROOT_URLCONF = 'alecdayupay_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 include, path
urlpatterns = [
path('admin/', admin.site.urls),
path('', include("bookshelf.urls")),
path('admin/', admin.site.urls)
]
from django.contrib import admin
from .models import Author, Books
# Register your models here.
class BooksInline(admin.TabularInline):
model = Books
class AuthorAdmin(admin.ModelAdmin):
model = Author
list_display = ("first_name", "last_name", "age", "nationality", "bio",)
inlines = [BooksInline]
class BooksAdmin(admin.ModelAdmin):
list_display = ("title", "author", "publisher", "year_published", "ISBN", "blurb",)
admin.site.register(Author, AuthorAdmin)
admin.site.register(Books, BooksAdmin)
\ No newline at end of file
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 04:11
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=50)),
('last_name', models.CharField(max_length=50)),
('age', models.IntegerField(default=0)),
('nationality', models.CharField(max_length=50)),
('bio', models.TextField(max_length=700)),
],
),
migrations.CreateModel(
name='Books',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('title', models.CharField(max_length=50)),
('publisher', models.CharField(max_length=50)),
('year_published', models.IntegerField(default=0)),
('ISBN', models.IntegerField(default=0)),
('blurb', models.TextField()),
('author', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='bookshelf.author')),
],
),
]
from django.db import models
# Create your models here.
class Author(models.Model):
first_name = models.CharField(max_length=50)
last_name = models.CharField(max_length=50)
age = models.IntegerField(default=0)
nationality = models.CharField(max_length=50)
bio = models.TextField(max_length=700)
class Books(models.Model):
title = models.CharField(max_length=50)
author = models.ForeignKey(Author, on_delete=models.CASCADE)
publisher = models.CharField(max_length=50)
year_published = models.IntegerField(default=0)
ISBN = models.IntegerField(default=0)
blurb = models.TextField()
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block title %}{{ object.first_name }} {{ object.last_name }}{% endblock %}
{% block heading %}{{ object.first_name }} {{ object.last_name }}{% endblock %}
{% block content %}
<p>{{ object.age }}</p>
<p>{{ object.nationality }}</p>
<p>{{ object.bio }}</p>
<p>Books by {{ object.first_name }} {{ object.last_name }} I love:</p>
{% for books in object.books_set.all %}
<li>
<a href="http://localhost:8000/books/{{ books.pk }}/details/">{{ books.title }}</a>
</li>
{% endfor %}
{% endblock %}
{% block links %}<a href="http://localhost:8000/home/">Home</a> <a href="http://localhost:8000/books/">Books</a> <a href="http://localhost:8000/authors/">Authors</a>{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block title %}My Favorite Authors{% endblock %}
{% block heading %}Alec's Favorite Authors:{% endblock %}
{% block content %}
{% for object in object_list %}
<li>
<a href="http://localhost:8000/authors/{{ object.pk }}/details/">{{ object.first_name }} {{ object.last_name }}</a>
</li>
{% endfor %}
{% endblock %}
{% block links %}<a href="http://localhost:8000/home/">Home</a> <a href="http://localhost:8000/books/">Books</a>{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block title %}{{ object.title }}{% endblock %}
{% block heading %}{{ object.title }}{% endblock %}
{% block content %}
<p><a href="http://localhost:8000/authors/{{ object.author.pk }}/details/">{{ object.author }}</a></p>
<p>{{ object.publisher }}</p>
<p>{{ object.year_published }}</p>
<p>{{ object.ISBN }}</p>
<p>{{ object.blurb }}</p>
{% endblock %}
{% block links %}<a href="http://localhost:8000/home/">Home</a> <a href="http://localhost:8000/books/">Books</a> <a href="http://localhost:8000/authors/">Authors</a>{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block title %}My Favorite Books{% endblock %}
{% block heading %}Alec's Favorite Books:{% endblock %}
{% block content %}
{% for object in object_list %}
<li>
<a href="http://localhost:8000/books/{{ object.pk }}/details/">{{ object.title }}</a>
</li>
{% endfor %}
{% endblock %}
{% block links %}<a href="http://localhost:8000/home/">Home</a> <a href="http://localhost:8000/authors/">Authors</a>{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block title %}My Favorite Books & Authors{% endblock %}
{% block heading %}Welcome to Alec's Database of Favorite Books and Authors{% endblock %}
{% block content %}
<p>
Some of these books I have only heard about from my sister and my girlfiend,
but the others I have only read as an assignment during middle and high school.
</p>
{% endblock %}
{% block links %}<a href="http://localhost:8000/books/">Books</a> <a href="http://localhost:8000/authors/">Authors</a>{% endblock %}
\ No newline at end of file
from django.test import TestCase
# Create your tests here.
from django.urls import path
from . import views
from .views import BooksListView, BooksDetailView, AuthorListView, AuthorDetailView
urlpatterns = [
path('home/', views.home, name="home"),
path('books/', BooksListView.as_view(), name="books_list"),
path('books/<int:pk>/details/', BooksDetailView.as_view(), name="books_detail"),
path('authors/', AuthorListView.as_view(), name="author_list"),
path('authors/<int:pk>/details/', AuthorDetailView.as_view(), name="author_detail")
]
\ No newline at end of file
from django.shortcuts import render
from django.views.generic.list import ListView
from django.views.generic.detail import DetailView
from .models import Author, Books
def home(request):
return render(request, "bookshelf/home.html")
class BooksListView(ListView):
model = Books
class BooksDetailView(DetailView):
model = Books
class AuthorListView(ListView):
model = Author
class AuthorDetailView(DetailView):
model = Author
\ No newline at end of file
<html>
<head>
<title>{% block title%}{% endblock %}</title>
</head>
<body>
<div id="heading">
<h1>{% block heading %}{% endblock %}</h1>
</div>
<div id="content">
{% block content %}{% endblock %}
</div>
<div id="links">
<pre>{% block links %}{% endblock %}</pre>
</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