Commit ebebefef authored by Albert Gagalac's avatar Albert Gagalac

Implemented working hyperlinks + finished all pages

parent 32d56472
...@@ -15,11 +15,11 @@ class Author(models.Model): ...@@ -15,11 +15,11 @@ 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', kwargs={'pk' : self.pk}) return reverse('bookshelf:author-detail', kwargs={'pk' : self.pk})
class Book(models.Model): class Book(models.Model):
title = models.CharField(default="", max_length=100) title = models.CharField(default="", max_length=100)
author = models.ForeignKey(Author, on_delete=models.CASCADE) author = models.ForeignKey(Author, on_delete=models.CASCADE, unique=True)
publisher = models.CharField(default="", max_length=100) publisher = models.CharField(default="", max_length=100)
ISBN = models.PositiveIntegerField(validators= ISBN = models.PositiveIntegerField(validators=
[RegexValidator(r'^[0-9]*$', [RegexValidator(r'^[0-9]*$',
...@@ -31,4 +31,7 @@ class Book(models.Model): ...@@ -31,4 +31,7 @@ class Book(models.Model):
return '{}'.format(self.title) return '{}'.format(self.title)
def get_absolute_url(self): def get_absolute_url(self):
return reverse('author', kwargs={'pk' : self.pk}) return reverse('bookshelf:books-detail', kwargs={'pk' : self.pk})
def get_home_url(self):
return reverse('bookshelf:books-list')
<p>{{"Widget's Assignments Page"}}<br><br></p>
{% for data in author %}
<p>
first_name: {{data.first_name}}<br>
last_name: {{data.last_name}}<br>
<br>
</p>
{% endfor %}
{% extends 'base.html' %}
{% load static %}
{% block css %} {% endblock %}
{% block title %}{{object}}{% endblock %}
{% block heading %}{{object}}{% endblock %}
{% block content %}
<ul>
<h3>Age:</h3> {{object.age}}<br>
<h3>Nationality:</h3> {{object.nationality}}<br>
<h3>Bio:</h3> {{object.bio}}
<br><br><br><a href="/home/ ">Home</a> | <a href="/books/ ">Books</a> | <a href="/author/ ">Authors</a>
</ul>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block css %}
h1 {
text-align: center;
padding-top: 175px;
font-family: "Comic Sans MS", cursive;
}
ul {
text-align: center;
font-family: "Arial", cursive;
}
{% endblock %}
{% block title %}My Favorite Authors{% endblock %}
{% block heading %}Burt's Favorite Authors{% endblock %}
{% block content %}
<ul>
{% for object in object_list %}
<a href="{{ object.get_absolute_url }}">
{{ object }}
</a> <br>
{% endfor %}<br>
<a href="/home/ ">Home</a> | <a href="/books/ ">Books</a> | <a href="/author/ ">Authors</a>
</ul>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block css %}
h1 {
text-align: center;
padding-top: 175px;
font-family: "Comic Sans MS", cursive;
}
p {
text-align: center;
font-family: "Arial", cursive;
}
{% endblock %}
{% block title %}{{object}}{% endblock %}
{% block heading %}{{object}}{% endblock %}
{% block content %}
<ul>
<h3>Author:</h3> {{object.author}}<br>
<h3>Publisher:</h3> {{object.publisher}}<br>
<h3>ISBN:</h3> {{object.ISBN}}<br>
<h3>Blurb:</h3> {{object.blurb}}
<br><br><br><a href="/home/ ">Home</a> | <a href="/books/ ">Books</a> | <a href="/author/ ">Authors</a>
</ul>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block css %}
h1 {
text-align: center;
padding-top: 175px;
font-family: "Comic Sans MS", cursive;
}
ul {
text-align: center;
font-family: "Arial", cursive;
}
{% endblock %}
{% block title %}My Favorite Books{% endblock %}
{% block heading %}Burt's Favorite Books{% endblock %}
{% block content %}
<ul>
{% for object in object_list %}
<a href="{{ object.get_absolute_url }}">{{object.title}}</a><br>
{% endfor %} <br><br>
<a href="/home/ ">Home</a> | <a href="/author/">Authors</a>
</ul>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block heading %}{% endblock %}
{% block content %}
<h1>Hello World. This is the content</h1>
{% endblock %}
\ No newline at end of file
{% extends "base.html" %} {% extends "base.html" %}
{% load static %} {% load static %}
{% comment %} {% block %} {% endblock %} {% endcomment %} {% comment %} {% block css %}
<style>
h1 {
text-align: center;
padding-top: 175px;
}
p {
text-align: center;
}
</style>
{% endblock %} {% endcomment %}
{% block css %}
h1 {
text-align: center;
padding-top: 175px;
font-family: "Comic Sans MS", cursive;
}
p {
text-align: center;
font-family: "Arial", cursive;
}
{% endblock %}
{% block title %} My Favorite Books and Authors {% endblock %}
{% block heading %} Welcome to <br>Burt's Database <br>of Favorite Books and Authors {% endblock %} {% block heading %} Welcome to <br>Burt's Database <br>of Favorite Books and Authors {% endblock %}
{% block content %} In the past I used to be an avid reader of <br> {% block content %} In the past I used to be an avid reader of <br>
Sci-Fi and Mythology type novels. In more recent times,<br> Sci-Fi and Mythology type novels. In more recent times,<br>
I have come to love more manga that deal with <br> I have come to love more manga that deal with <br>
down-to-earth and realistic themes. <br> <br> down-to-earth and realistic themes. <br> <br>
tl;dr: I now weeb <br> <br> <br> tl;dr: I now weeb <br> <br> <br>
Books | Authors <a href="/books/ ">Books</a> | <a href="/author/">Authors</a>
{% endblock %} {% endblock %}
{% block list %} {% endblock %}
\ No newline at end of file
from django.urls import path from django.urls import path
from .views import author, BookPageView, home from .views import (
AuthorDetailView, BookDetailView,
home, BookListView, AuthorListView
)
urlpatterns = [ urlpatterns = [
path('', home, name='home'), path('', home, name='home'),
path("author/", author, name="author"), path('home/', home, name='home'),
path("books/", BookPageView.as_view(), name="books"), path("author/", AuthorListView.as_view(), name="author-list"),
path("books/", BookListView.as_view(), name="books-list"),
path("books/<int:pk>/details", BookDetailView.as_view(), name="books-detail"),
path("author/<int:pk>/details", AuthorDetailView.as_view(), name="author-detail"),
] ]
app_name = "bookshelf" app_name = "bookshelf"
\ No newline at end of file
...@@ -5,17 +5,19 @@ from django.views.generic.detail import DetailView ...@@ -5,17 +5,19 @@ 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(request): def home(request):
return render(request, 'bookshelf/home.html') return render(request, 'bookshelf/home.html')
def author(request): class BookDetailView(DetailView):
author = Author.objects.all() model = Book
return render(request, 'bookshelf/author.html', {'author' : author})
class AuthorDetailView(DetailView):
model = Author
class BookListView(ListView):
model = Book
class BookPageView(View): class AuthorListView(ListView):
def get(self, request): model = Author
books = Book.objects.order_by('title')
return render(request, 'bookshelf/books.html', {'books' : books})
...@@ -2,25 +2,19 @@ ...@@ -2,25 +2,19 @@
<html lang="en"> <html lang="en">
<head> <head>
<style> <style>
h1 { {% block css %}
text-align: center; body {background: rgba(255, 207, 51, 0.938);}
padding-top: 175px; {% endblock %}
} </style>
p {
text-align: center;
}
</style>
<link rel="stylesheet" href="style.css"> <link rel="stylesheet" href="style.css">
<title>{% block title %}Burt's Book Bemporium{% endblock %}</title> <title>{% block title %}Burt's Book Bemporium{% endblock %}</title>
{% block styles %}{% endblock %}
</head> </head>
<body> <body>
<h1>{% block heading %} {% endblock %}</h1> <h1>{% block heading %}{% endblock %}</h1>
<div id="content"> <div id="content">
<p>{% block content %}{% endblock %}</p> <p>{% block content %}{% endblock %}</p>
</div> </div>
{% block list %}{% endblock %}
{% block scripts %}{% endblock %}
</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