Commit ebf98e06 authored by Jenica Vizmanos's avatar Jenica Vizmanos

Created Templates and URLS and modified the necessary files according to lab specifications

parent 205b117f
**/.env
.env
.gitignore
db.sqlite3
**/**__pycache__
\ No newline at end of file
**/__pycache__
**/**/__pycache__
\ No newline at end of file
from django.contrib import admin
from .models import Author, Book
from .models import Author, Books
class AuthorAdmin(admin.ModelAdmin):
model = Author
......@@ -7,11 +7,11 @@ class AuthorAdmin(admin.ModelAdmin):
list_display = ('first_name', 'last_name', 'nationality',)
list_filter = ('first_name', 'last_name', 'nationality',)
class BookAdmin(admin.ModelAdmin):
model = Book
class BooksAdmin(admin.ModelAdmin):
model = Books
search_fields = ('title', 'publisher',)
list_display = ('title', 'publisher', 'year_published', 'ISBN',)
list_filter = ('title', 'publisher', 'year_published',)
admin.site.register(Author, AuthorAdmin)
admin.site.register(Book, BookAdmin)
admin.site.register(Books, BooksAdmin)
# Generated by Django 4.1.6 on 2023-03-28 07:48
import django.core.validators
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("bookshelf", "0002_rename_books_book"),
]
operations = [
migrations.AlterField(
model_name="book",
name="blurb",
field=models.TextField(
default="",
max_length=800,
validators=[
django.core.validators.MinLengthValidator(
400, "The field must contain at least 400 characters."
)
],
),
),
]
# Generated by Django 4.1.6 on 2023-03-28 07:50
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("bookshelf", "0003_alter_book_blurb"),
]
operations = [
migrations.AlterField(
model_name="book",
name="blurb",
field=models.TextField(default="", max_length=800),
),
]
# Generated by Django 4.1.6 on 2023-03-28 11:44
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
("bookshelf", "0004_alter_book_blurb"),
]
operations = [
migrations.RenameModel(old_name="Book", new_name="Books",),
]
# Generated by Django 4.1.6 on 2023-03-28 12:29
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
("bookshelf", "0005_rename_book_books"),
]
operations = [
migrations.AlterField(
model_name="books",
name="author",
field=models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="book",
to="bookshelf.author",
),
),
]
# Generated by Django 4.1.6 on 2023-03-28 12:40
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
("bookshelf", "0006_alter_books_author"),
]
operations = [
migrations.AlterField(
model_name="books",
name="author",
field=models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="writings",
to="bookshelf.author",
),
),
]
from django.db import models
from django.urls import reverse
from django.core.validators import MaxValueValidator
class Author(models.Model):
......@@ -9,15 +10,21 @@ class Author(models.Model):
bio = models.TextField(max_length=700, default='')
def __str__(self):
return 'Author Name: {} {}'.format(self.first_name, self.last_name)
return '{} {}'.format(self.first_name, self.last_name)
def get_absolute_url(self):
return reverse('bookshelf:author_details', kwargs={'pk': self.pk})
class Book(models.Model):
class Books(models.Model):
title = models.CharField(max_length=255, default='')
author = models.ForeignKey(Author, on_delete=models.CASCADE)
author = models.ForeignKey(Author, on_delete=models.CASCADE, related_name='writings')
publisher = models.CharField(max_length=255, default='')
year_published = models.PositiveIntegerField(default=0)
ISBN = models.PositiveBigIntegerField(validators=[MaxValueValidator(9999999999999)], default=0)
blurb = models.TextField(max_length=800, default='')
def __str__(self):
return 'Book Name: {}'.format(self.title)
\ No newline at end of file
return '{}'.format(self.title)
def get_absolute_url(self):
return reverse('bookshelf:book_details', kwargs={'pk': self.pk})
\ No newline at end of file
{% extends 'base.html' %}
{% block title %}{{ object }}{% endblock %}
{% block content %}
<h1>{{ object }}</h1>
<p>
{{ object.age }}<br>
{{ object.nationality }}<br>
{{ object.bio }}<br><br>
Books by {{ object }} I love:
<ul>
{% for book in object.writings.all %}
<li>
<a href='{{ book.get_absolute_url }}'>{{ book }}</a>
</li>
{% endfor %}
</ul><br><br>
<a href='/bookshelf/home/'>Home</a>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp
<a href='/bookshelf/books/'>Books</a>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<a href='/bookshelf/authors/'>Authors</a>
</p>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% block title %}My Favorite Authors{% endblock %}
{% block content %}
<h1>Jenica's Favorite Authors:</h1>
<ul>
{% for object in object_list %}
<li>
<a href='{{ object.get_absolute_url }}'>{{ object }}</a>
</li>
{% endfor %}
</ul>
<p>
<a href='/bookshelf/home/'>Home</a>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<a href='/bookshelf/books/'>Books</a>
</p>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% block title %}{{ object }}{% endblock %}
{% block content %}
<h1>{{ object }}</h1>
<p>
<a href='{{ object.author.get_absolute_url }}'>{{ object.author }}</a><br>
{{ object.publisher }}<br>
{{ object.year_published }}<br>
{{ object.ISBN }}<br>
{{ object.blurb }}<br><br>
<a href='/bookshelf/home/'>Home</a>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp
<a href='/bookshelf/books/'>Books</a>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<a href='/bookshelf/authors/'>Authors</a>
</p>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% block title %}My Favorite Books{% endblock %}
{% block content %}
<h1>Jenica's Favorite Books:</h1>
<ul>
{% for object in object_list %}
<li>
<a href='{{ object.get_absolute_url }}'>{{ object }}</a>
</li>
{% endfor %}
</ul>
<p>
<a href='/bookshelf/home/'>Home</a>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<a href='/bookshelf/authors/'>Authors</a>
</p>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% block title %}My Favorite Books & Authors{% endblock %}
{% block content %}
<h1>Welcome to {{ nickname }}'s Database of Favorite Books and Authors!</h1>
<p>
{{ description }}<br><br>
<a href='/bookshelf/books/'>Books</a>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp
<a href='/bookshelf/authors/'>Authors</a>
</p>
{% endblock %}
\ No newline at end of file
from django.urls import path
from .views import home_view, AuthorListView, AuthorDetailView, BooksListView, BooksDetailView
urlpatterns = [
path('home/', home_view, name='home_view'),
path('authors/', AuthorListView.as_view(), name='authors'),
path('authors/<int:pk>/details/', AuthorDetailView.as_view(), name='author_details'),
path('books/', BooksListView.as_view(), name='books'),
path('books/<int:pk>/details/', BooksDetailView.as_view(), name='book_details'),
]
app_name = 'bookshelf'
\ No newline at end of file
from django.shortcuts import render
from django.views.generic.detail import DetailView
from django.views.generic.list import ListView
from .models import Author, Books
# Create your views here.
def home_view(request):
return render(request, 'bookshelf/home.html', {
'nickname': 'Jenica',
'description': 'I enjoy classical and adventure books. One of the authors who appeal to me is Mark Twain.'
})
class AuthorListView(ListView):
model = Author
template_name = 'bookshelf/authors.html'
class AuthorDetailView(DetailView):
model = Author
template_name = 'bookshelf/author_details.html'
class BooksListView(ListView):
model = Books
template_name = 'bookshelf/books.html'
class BooksDetailView(DetailView):
model = Books
template_name = 'bookshelf/book_details.html'
\ No newline at end of file
......@@ -58,7 +58,7 @@ ROOT_URLCONF = "jenicavizmanos_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 path, include
urlpatterns = [
path("admin/", admin.site.urls),
path("bookshelf/", include('bookshelf.urls', namespace='bookshelf')),
]
<html lang="en">
<head>
<title>{% block title %}{% endblock %}</title>
</head>
<body>
{% block content %}{% 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