Commit d14289a0 authored by Ian Rafael T. Aragoza's avatar Ian Rafael T. Aragoza

Made list and detail webpages with hyperlinks.

parent b2eea795
...@@ -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', args=[str(self.last_name)]) return f"{self.pk}"
class Book(models.Model): class Book(models.Model):
...@@ -30,4 +30,4 @@ class Book(models.Model): ...@@ -30,4 +30,4 @@ class Book(models.Model):
return '{}'.format(self.title) return '{}'.format(self.title)
def get_absolute_url(self): def get_absolute_url(self):
return reverse('book_detail', args=[str(self.title)]) return f"{self.pk}"
{% extends 'base.html' %}
{% load static %}
{% block title %}{{ object.first_name }} {{ object.last_name }}{% endblock %}
{% block content %}
<h1>{{ object.first_name }} {{ object.last_name }}</h1>
<p>Age: {{ object.age }}</p>
<p>Nationality: {{ object.nationality }}</p>
<p>{{ object.bio | linebreaks }}</p>
<h3>Books by {{ object.first_name }} {{ object.last_name }} I Love:</h3>
{% for book in object.books.all %}
<p><a href="../../../../books/{{ book.get_absolute_url }}/details/"> {{ book.title }}</a></p>
{% endfor %}
<a href="/home"><p>Home</p></a>
<a href="/books"><p>Books</p></a>
<a href="/authors"><p>Authors</p></a>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block title %}My Favorite Books{% endblock %}
{% block content %}
<h1>Ian's Favorite Authors:</h1>
{% for object in object_list %}
<p><a href="{{ object.get_absolute_url }}/details/">{{ object.first_name }} {{ object.last_name }}</a></p>
{% endfor %}
<a href="/home"><p>Home</p></a>
<a href="/books"><p>Books</p></a>
{% endblock %}
\ No newline at end of file
<html lang="en">
<head>
<link rel="stylesheet" href="style.css">
<title>{% block title %}My amazing site{% 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
{% extends 'base.html' %}
{% load static %}
{% block title %}{{ object.title }}{% endblock %}
{% block content %}
<h1>{{ object.title }}</h1>
<p><a href="../../../../authors/{{ object.author.get_absolute_url }}/details/">{{ object.author }}</a></p>
<p>{{ object.publisher }}</p>
<p>{{ object.year_published }}</p>
<p>{{ object.ISBN }}</p>
<p>{{ object.blurb | linebreaks}}</p>
<a href="/home"><p>Home</p></a>
<a href="/books"><p>Books</p></a>
<a href="/authors"><p>Authors</p></a>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block title %}My Favorite Books{% endblock %}
{% block content %}
<h1>Ian's Favorite Books:</h1>
{% for object in object_list %}
<p><a href="{{ object.get_absolute_url }}/details/">{{ object.title }}</a></p>
{% endfor %}
<a href="/home"><p>Home</p></a>
<a href="/authors"><p>Authors</p></a>
{% endblock %}
\ No newline at end of file
...@@ -2,11 +2,11 @@ ...@@ -2,11 +2,11 @@
{% load static %} {% load static %}
{% block title %}My Favorite Books and Authors{% endblock %} {% block title %}My Favorite Books and Authors{% endblock %}
{% block content %} {% block content %}
<h1>Welcome to Ian's Database of Favorite Books and Authors!</h1> <h1>Welcome to {{ name }}'s Database of Favorite Books and Authors!</h1>
<p>These past few years, I've hadn't really had the chance to sit down and enjoy a good book. That said, that doesn't mean there aren't those that mean a lot to me.</p> <p>These past few years, I've hadn't really had the chance to sit down and enjoy a good book. That said, that doesn't mean there aren't those that mean a lot to me.</p>
<p>The books I've chosen come from different points of my life, and you can see some of them show qualities that I had like whimsy, angsty, or... gay? <br> <p>The books I've chosen come from different points of my life, and you can see some of them show qualities that I had like whimsy, angsty, or... gay? <br>
No matter the case, I've had adventures with each of these books, and even though I don't remember them well, they've still left a mark on me.</p> No matter the case, I've had adventures with each of these books, and even though I don't remember them well, they've still left a mark on me.</p>
<a href="/books"><p>Books</p></a> <a href="/books"><p>Books</p></a>
<a href="/auhtors"><p>Authors</p></a> <a href="/authors"><p>Authors</p></a>
{% endblock %} {% endblock %}
\ No newline at end of file
# <appname>/urls.py # <appname>/urls.py
from django.urls import path from django.urls import path
from .views import index from .views import home, AuthorsView, AuthorDetailsView, BooksView, BookDetailsView
urlpatterns = [ urlpatterns = [
path('', index, name='index'), path('home/', home, name='home'),
path('authors/', AuthorsView.as_view(), name='author-list'),
path('authors/<int:pk>/details/', AuthorDetailsView.as_view(), name='author-detail'),
path('books/', BooksView.as_view(), name='books-list'),
path('books/<int:pk>/details/', BookDetailsView.as_view(), name='books-detail'),
] ]
......
from django.shortcuts import render from django.shortcuts import render
from django.views.generic.detail import DetailView
from django.views.generic.list import ListView
# Create your views here.
from django.http import HttpResponse from .models import Author, Book
def index(request): # Create your views here.
def home(request):
return render(request, 'home.html', {'name': 'Ian'}) return render(request, 'home.html', {'name': 'Ian'})
class BooksView(ListView):
model = Book
class BookDetailsView(DetailView):
model = Book
class AuthorsView(ListView):
model = Author
class AuthorDetailsView(DetailView):
model = Author
...@@ -16,7 +16,8 @@ Including another URLconf ...@@ -16,7 +16,8 @@ Including another URLconf
from django.contrib import admin from django.contrib import admin
from django.urls import path, include from django.urls import path, include
urlpatterns = [ urlpatterns = [
path('admin/', admin.site.urls), path('admin/', admin.site.urls),
path('home/', include('bookshelf.urls', namespace="bookshelf")), path('', include('bookshelf.urls', namespace="bookshelf")),
] ]
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