finished authors & book htmls

parent 21df84fe
# Generated by Django 4.1.7 on 2023-03-28 16:56
import django.core.validators
from django.db import migrations, models
import django.db.models.deletion
import re
class Migration(migrations.Migration):
dependencies = [
('bookshelf', '0005_alter_books_isbn'),
]
operations = [
migrations.CreateModel(
name='Book',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('title', models.CharField(default='', max_length=200)),
('publisher', models.CharField(default='', max_length=200)),
('year_published', models.IntegerField(default=2023, validators=[django.core.validators.MaxValueValidator(2023)])),
('ISBN', models.CharField(default='0000000000000', max_length=13, validators=[django.core.validators.RegexValidator(re.compile('^\\d+(?:\\d+)*\\Z'), code='invalid', message=None), django.core.validators.MinLengthValidator(13)])),
('blurb', models.TextField(max_length=400, validators=[django.core.validators.MinLengthValidator(100)])),
('author', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='bookshelf.author')),
],
),
migrations.DeleteModel(
name='Books',
),
]
# Generated by Django 4.1.7 on 2023-03-28 17:30
import django.core.validators
from django.db import migrations, models
import re
class Migration(migrations.Migration):
dependencies = [
('bookshelf', '0006_book_delete_books'),
]
operations = [
migrations.AlterField(
model_name='book',
name='ISBN',
field=models.CharField(default='0000000000000', max_length=13, validators=[django.core.validators.RegexValidator(re.compile('^\\d+(?:\\d+)*\\Z'), code='invalid', message=None), django.core.validators.MinLengthValidator(13), django.core.validators.MaxLengthValidator(13)]),
),
]
......@@ -15,7 +15,7 @@ class Author(models.Model):
return '{} {}'.format(self.first_name, self.last_name)
def get_absolute_url(self):
return reverse('author-detail', kwargs={'pk': self.pk})
return reverse('bookshelf:author-detail', kwargs={'pk': self.pk})
class Book(models.Model):
......@@ -29,7 +29,7 @@ class Book(models.Model):
year_published = models.IntegerField(validators=[MaxValueValidator(datetime.datetime.now().year)], default = datetime.datetime.now().year)
#Source: https://stackoverflow.com/questions/57131043/how-to-make-integer-field-fixed-to-ten-numbers-output-in-models
ISBN = models.CharField(max_length=13, validators=[int_list_validator(sep=''),MinLengthValidator(13),], default='0000000000000')
ISBN = models.CharField(max_length=13, validators=[int_list_validator(sep=''),MinLengthValidator(13),MaxLengthValidator(13)], default='0000000000000')
blurb = models.TextField(validators=[MinLengthValidator(100)], max_length=400)
......@@ -38,5 +38,5 @@ class Book(models.Model):
return '{} by {}'.format(self.title, self.author)
def get_absolute_url(self):
return reverse('book-detail', kwargs={'pk': self.pk})
return reverse('bookshelf:book-detail', kwargs={'pk': self.pk})
......@@ -8,8 +8,8 @@ Chris's Favorite Authors:
{%block hyperlinks%}
<ul>
{% for i in author_list %}
<li><a href="url">{{i.first_name}} {{i.last_name}}</a></li>
{% for object in object_list %}
<li><a href="{{object.get_absolute_url}}">{{object.first_name}} {{object.last_name}}</a></li>
{% endfor %}
<br></br>
<a href="/home">Home</a>
......
{% 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
......@@ -8,8 +8,8 @@ Chris's Favorite Books:
{%block hyperlinks%}
<ul>
{% for i in book_list %}
<li><a href="/{{book_list.get_absolute_url}}/details">{{i.title}}</a></li>
{% for object in object_list %}
<li><a href="{{object.get_absolute_url}}">{{object.title}}</a></li>
{% endfor %}
<br></br>
<a href="/home">Home</a>
......
from django.urls import path
from .views import home_view, BooksListView, AuthorsListView, BookDetailsView, AuthorDetailsView
from .views import home_view, BookListView, AuthorsListView, BookDetailsView, AuthorDetailsView
urlpatterns = [
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('books/', BookListView.as_view(), name ="book-list"),
path('books/<int:pk>/details/', BookDetailsView.as_view(), name ="book-detail"),
path('authors/', AuthorsListView.as_view(), name ="My Favorite Authors"),
path('authors/', AuthorsListView.as_view(), name ="author-list"),
path('authors/<int:pk>/details/', AuthorDetailsView.as_view(), name ="author-detail"),
]
app_name = "bookshelf"
\ No newline at end of file
app_name = 'bookshelf'
\ No newline at end of file
from django.shortcuts import render
from django.views import View
from django.views.generic.list import ListView, DetailView
from django.views.generic.list import ListView
from django.views.generic.detail import DetailView
from .models import Author, Book
# Create your views here.
def home_view(request):
return render(request, 'bookshelf/home.html', {})
class BooksListView(ListView):
class BookListView(ListView):
template_name = "bookshelf/books.html"
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):
template_name = "bookshelf/book_details.html"
model = Book
class AuthorsListView(ListView):
template_name = "bookshelf/authors.html"
model = Author
class AuthorDetailsView(DetailView):
model = Author
\ No newline at end of file
template_name = "bookshelf/author_details.html"
model = Author
def get_context_data(self, **kwargs):
# Call the base implementation first to get a context
context = super().get_context_data(**kwargs)
# Add in a QuerySet of all the books
context['book_list'] = Book.objects.all()
return context
\ No newline at end of file
......@@ -6,13 +6,13 @@
</head>
<body>
<div id="heading">
<h1>{% block heading %}{% endblock %}</h1>
<ul><ul><h1>{% block heading %}{% endblock %}</h1></ul></ul>
</div>
<div id="text">
{% block text %}{% endblock %}
</div>
<div id="hyperlinks">
{% block hyperlinks %}{% endblock %}
<ul><ul>{% block hyperlinks %}{% endblock %}</ul></ul>
</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