Commit 959a28bf authored by Ross Batacan's avatar Ross Batacan

modified models.py, created project-level template base.html, and app-level...

modified models.py, created project-level template base.html, and app-level templates books.html and home.html
parent 219c51c4
# Generated by Django 3.2 on 2023-03-28 12:32
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('bookshelf', '0001_initial'),
]
operations = [
migrations.AlterField(
model_name='author',
name='last_name',
field=models.CharField(max_length=30),
),
migrations.AlterField(
model_name='books',
name='ISBN',
field=models.CharField(max_length=14, null=True),
),
]
# Generated by Django 3.2 on 2023-03-28 12:47
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('bookshelf', '0002_auto_20230328_2032'),
]
operations = [
migrations.AlterField(
model_name='books',
name='blurb',
field=models.CharField(max_length=700, null=True),
),
]
from django.db import models from django.db import models
from django.urls import reverse
# Create your models here. # Create your models here.
class Author(models.Model): class Author(models.Model):
first_name = models.CharField(max_length=30,) first_name = models.CharField(max_length=30)
last_name = models.CharField(max_length=30, unique=True) last_name = models.CharField(max_length=30)
age = models.IntegerField(null=True) age = models.IntegerField(null=True)
nationality = models.CharField(max_length=30, null=True) nationality = models.CharField(max_length=30, null=True)
bio = models.CharField(max_length=700, null=True) bio = models.CharField(max_length=700, null=True)
...@@ -13,14 +14,20 @@ class Author(models.Model): ...@@ -13,14 +14,20 @@ class Author(models.Model):
def __str__(self): def __str__(self):
return self.first_name return self.first_name
def get_absolute_url(self):
return self.last_name
class Books(models.Model): class Books(models.Model):
title = models.CharField(max_length=100, unique=True, null=True) title = models.CharField(max_length=100, unique=True, null=True)
author = models.ForeignKey(Author, on_delete=models.CASCADE, null=True) author = models.ForeignKey(Author, on_delete=models.CASCADE, null=True)
publisher = models.CharField(max_length=50, null=True) publisher = models.CharField(max_length=50, null=True)
year_published = models.IntegerField(null=True) year_published = models.IntegerField(null=True)
ISBN = models.IntegerField(null=True) ISBN = models.CharField(max_length=14, null=True)
blurb = models.CharField(max_length=200, null=True) blurb = models.CharField(max_length=700, null=True)
def __str__(self): def __str__(self):
return self.album_name return self.title
def get_absolute_url(self):
return self.title
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>The Books</title>
</head>
<body>
</body>
</html>
\ No newline at end of file
{% extends 'base.html' %}
{% block title %}My Favorite Books & Authors{% endblock %}
{% block content %}
<h1>Welcome to Ross's Database of Favorite Books and Authors!</h1>
<h3>I like books, books, and books. My recent read was Tuesdays with Morrie by
Mitch Albom</h3>
<a href="{% url 'bookshelf:books' %}">Books</a> <br>
<a href="{% url 'bookshelf:authors' %}">Authors</a>
{% endblock %}
from django.urls import path
from . import views
from .views import BooksListView, BooksDetailsView, AuthorsListView, AuthorDetailsView
urlpatterns = [
path('home/', views.home, name = "home"),
path('books/', BooksListView.as_view(), name = "books"),
path('books/<int:pk>/details/', BooksDetailsView.as_view(), name = "book-detail"),
path('authors/', AuthorsListView.as_view(), name = "authors"),
path('authors/<int:pk>/details', AuthorDetailsView.as_view(), name = "author-detail"),
]
app_name = 'bookshelf'
from django.shortcuts import render from django.shortcuts import render
from django.views.generic.list import ListView
from django.views.generic.detail import DetailView
from .models import Author, Books
# Create your views here. # Create your views here.
def home(request):
return render(request, 'bookshelf/home.html')
class BooksListView(ListView):
model = Books
template_name = 'bookshelf/books.html'
class BooksDetailsView(DetailView):
model = Author
template_name = 'bookshelf/book_details.html'
class AuthorsListView(ListView):
model = Author
template_name = 'bookshelf/authors.html'
class AuthorDetailsView(DetailView):
model = Author
template_name = 'bookshelf/author_details'
\ No newline at end of file
...@@ -18,4 +18,5 @@ from django.urls import path, include ...@@ -18,4 +18,5 @@ from django.urls import path, include
urlpatterns = [ urlpatterns = [
path('admin/', admin.site.urls), path('admin/', admin.site.urls),
path('', include("bookshelf.urls"))
] ]
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" href="style.css">
<title>{% block title %}Ross's 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