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): ...@@ -15,7 +15,7 @@ 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('author-detail', kwargs={'pk': self.pk}) return reverse('bookshelf:author-detail', kwargs={'pk': self.pk})
class Book(models.Model): class Book(models.Model):
...@@ -29,7 +29,7 @@ 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) 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 #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) blurb = models.TextField(validators=[MinLengthValidator(100)], max_length=400)
...@@ -38,5 +38,5 @@ class Book(models.Model): ...@@ -38,5 +38,5 @@ class Book(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('book-detail', kwargs={'pk': self.pk}) return reverse('bookshelf:book-detail', kwargs={'pk': self.pk})
...@@ -8,8 +8,8 @@ Chris's Favorite Authors: ...@@ -8,8 +8,8 @@ Chris's Favorite Authors:
{%block hyperlinks%} {%block hyperlinks%}
<ul> <ul>
{% for i in author_list %} {% for object in object_list %}
<li><a href="url">{{i.first_name}} {{i.last_name}}</a></li> <li><a href="{{object.get_absolute_url}}">{{object.first_name}} {{object.last_name}}</a></li>
{% endfor %} {% endfor %}
<br></br> <br></br>
<a href="/home">Home</a> <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: ...@@ -8,8 +8,8 @@ Chris's Favorite Books:
{%block hyperlinks%} {%block hyperlinks%}
<ul> <ul>
{% for i in book_list %} {% for object in object_list %}
<li><a href="/{{book_list.get_absolute_url}}/details">{{i.title}}</a></li> <li><a href="{{object.get_absolute_url}}">{{object.title}}</a></li>
{% endfor %} {% endfor %}
<br></br> <br></br>
<a href="/home">Home</a> <a href="/home">Home</a>
......
from django.urls import path from django.urls import path
from .views import home_view, BooksListView, AuthorsListView, BookDetailsView, AuthorDetailsView from .views import home_view, BookListView, AuthorsListView, BookDetailsView, AuthorDetailsView
urlpatterns = [ urlpatterns = [
path('', home_view, name="My Favorite Books & Authors"), path('', home_view, name="My Favorite Books & Authors"),
path('home/', 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/', BookListView.as_view(), name ="book-list"),
path('books/<int:pk>/details/', BookDetailsView.as_view(), name ="book-item"), 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" app_name = 'bookshelf'
\ No newline at end of file \ No newline at end of file
from django.shortcuts import render from django.shortcuts import render
from django.views import View from django.views.generic.list import ListView
from django.views.generic.list import ListView, DetailView from django.views.generic.detail import DetailView
from .models import Author, Book from .models import Author, Book
# Create your views here. # Create your views here.
def home_view(request): def home_view(request):
return render(request, 'bookshelf/home.html', {}) return render(request, 'bookshelf/home.html', {})
class BooksListView(ListView): class BookListView(ListView):
template_name = "bookshelf/books.html"
model = Book 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): class BookDetailsView(DetailView):
template_name = "bookshelf/book_details.html"
model = Book model = Book
class AuthorsListView(ListView):
template_name = "bookshelf/authors.html"
model = Author
class AuthorDetailsView(DetailView): class AuthorDetailsView(DetailView):
model = Author template_name = "bookshelf/author_details.html"
\ No newline at end of file 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 @@ ...@@ -6,13 +6,13 @@
</head> </head>
<body> <body>
<div id="heading"> <div id="heading">
<h1>{% block heading %}{% endblock %}</h1> <ul><ul><h1>{% block heading %}{% endblock %}</h1></ul></ul>
</div> </div>
<div id="text"> <div id="text">
{% block text %}{% endblock %} {% block text %}{% endblock %}
</div> </div>
<div id="hyperlinks"> <div id="hyperlinks">
{% block hyperlinks %}{% endblock %} <ul><ul>{% block hyperlinks %}{% endblock %}</ul></ul>
</div> </div>
</body> </body>
</html> </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