Commit 3d02691a authored by Joei Yucoco's avatar Joei Yucoco

Configured footer page urls in bookshelf's templates

parent f4799a69
from django.db import models
from django.urls import reverse
class Author(models.Model):
#for repetitive get_absolute_url functions
class URLFunctions:
def get_absolute_AuthorsList_url(self):
return reverse('bookshelf:authors-list')
def get_absolute_BooksList_url(self):
return reverse('bookshelf:books-list')
def get_absolute_home_url(self):
return reverse('bookshelf:home')
class Author(models.Model,URLFunctions):
first_name = models.CharField(max_length=100)
last_name = models.CharField(max_length=100)
age = models.IntegerField()
......@@ -10,12 +24,28 @@ class Author(models.Model):
def __str__(self):
return '{} {}'.format(self.first_name, self.last_name)
class Books(models.Model):
def get_absolute_detail_url(self):
return reverse('bookshelf:authors-detail', kwargs={'pk':self.pk})
#def get_absolute_list_url(self):
#return reverse('bookshelf:authors-list')
class Books(models.Model,URLFunctions):
title = models.CharField(max_length=100)
author = models.ForeignKey(Author, on_delete=models.CASCADE)
publisher = models.CharField(max_length=100)
year_published = models.IntegerField()
ISBN = models.CharField(max_length=13)
blurb = models.TextField(max_length=700)
def __str__(self):
return '{}'.format(self.title)
def get_absolute_detail_url(self):
return reverse('bookshelf:books-detail', kwargs={'pk':self.pk})
#def get_absolute_list_url(self):
#return reverse('bookshelf:books-list')
# Create your models here.
......@@ -2,5 +2,20 @@
{% extends 'base.html' %}
{% block title %}My Favorite Books and Authors{% endblock %}
{% block content %}
<h1>Hello author details</h1>
<h1>Hello author details</h1>
<h2> {{object}} </h2>
<h3>
<a href="{{ object.get_absolute_home_url }}" >
Home
</a>
&nbsp;&nbsp;&nbsp;
<a href="{{ object.get_absolute_BooksList_url }}" >
Books
</a>
&nbsp;&nbsp;&nbsp;
<a href="{{ object.get_absolute_AuthorsList_url }}" >
Authors
</a>
</h3>
{% endblock %}
......@@ -2,5 +2,24 @@
{% extends 'base.html' %}
{% block title %}My Favorite Books and Authors{% endblock %}
{% block content %}
<h1>Hello authors</h1>
<h1>Hello authors</h1>
<ul>
{% for object in object_list %}
<li>
<a href="{{ object.get_absolute_detail_url }}" >
{{ object }}
</a>
</li>
{% endfor %}
</ul>
<h3>
<a href="{{ object_list.0.get_absolute_home_url }}" >
Home
</a>
&nbsp;&nbsp;&nbsp;
<a href="{{ object_list.0.get_absolute_BooksList_url }}" >
Books
</a>
</h3>
{% endblock %}
<!DOCTYPE html>
{% extends 'base.html' %}
{% block title %}My Favorite Books and Authors{% endblock %}
{% block title %}{{ object }}{% endblock %}
{% block content %}
<h1>Hello book details</h1>
<h1>Hello book details</h1>
<h2> {{object}} </h2>
<h3>
<a href="{{ object.get_absolute_home_url }}" >
Home
</a>
&nbsp;&nbsp;&nbsp;
<a href="{{ object.get_absolute_BooksList_url }}" >
Books
</a>
&nbsp;&nbsp;&nbsp;
<a href="{{ object.get_absolute_AuthorsList_url }}" >
Authors
</a>
</h3>
{% endblock %}
<!DOCTYPE html>
{% extends 'base.html' %}
{% block title %}My Favorite Books and Authors{% endblock %}
{% block title %}My Favorite Books{% endblock %}
{% block content %}
<h1>Hello books</h1>
<h1>Joei's Favorite Books</h1>
<ul>
{% for object in object_list %}
<li>
<a href="{{ object.get_absolute_detail_url }}" >
{{ object }}
</a>
</li>
{% endfor %}
</ul>
<h3>
<a href="{{ object_list.0.get_absolute_home_url }}" >
Home
</a>
&nbsp;&nbsp;&nbsp;
<a href="{{ object_list.0.get_absolute_AuthorsList_url }}" >
Authors
</a>
</h3>
{% endblock %}
......@@ -2,7 +2,23 @@
{% extends 'base.html' %}
{% block title %}My Favorite Books and Authors{% endblock %}
{% block content %}
<h1>Welcome to Joei's Database of</h1>
<h1>Favorite Books and Authors</h1>
<h3>I like books that look interesting...</h3>
<center>
<h1>Welcome to Joei's Database of<br>
Favorite Books and Authors</h1>
<h3>I like stuff that aren't boring</h3>
<br>
<h3>
<a href="{{ book.get_absolute_BooksList_url }}" >
Books
</a>
&nbsp;&nbsp;&nbsp;
<a href="{{ author.get_absolute_AuthorsList_url }}" >
Authors
</a>
</h3>
</center>
{% endblock %}
......@@ -10,7 +10,9 @@ from .models import Author, Books
#return HttpResponse('Hello World!')
def HomeView(request):
return render(request, 'bookshelf/home.html', {})
return render(request, 'bookshelf/home.html', {
'book': Books,
'author': Author})
class BooksView(ListView):
model = Books
......
......@@ -20,7 +20,7 @@ from django.urls import include, path
urlpatterns = [
#path('home/', include('bookshelf.urls', namespace="home")),
#path('home/', HomeView.as_view(), name='home'),
path('bookshelf/', include('bookshelf.urls', namespace="bookshelf")),
#path('bookshelf/', include('bookshelf.urls', namespace="bookshelf")),
path('', include('bookshelf.urls', namespace="basic")),
path('admin/', admin.site.urls),
]
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