Commit ae15e8ac authored by Rafa Mendoza's avatar Rafa Mendoza

added html pages

parent fec011a4
from django.db import models
# -- coding: UTF-8 --
from django.urls import reverse
class Author(models.Model):
......@@ -10,14 +10,14 @@ class Author(models.Model):
bio = models.CharField(max_length=700)
def __str__(self):
return '''{}, {}, {}, {}, {}'''.format(
return '''{} {}'''.format(
self.first_name,
self.last_name,
self.age,
self.nationality,
self.bio,
)
def get_absolute_url(self):
return reverse('bookshelf:author_details', kwargs={'pk': self.pk})
class Books(models.Model):
title = models.CharField(max_length=125)
......@@ -28,11 +28,9 @@ class Books(models.Model):
blurb = models.TextField()
def __str__(self):
return '''{}, {}, {}, {}, {}, {}'''.format(
return '''{}'''.format(
self.title,
self.author,
self.publisher,
self.year_published,
self.isbn,
self.blurb,
)
def get_absolute_url(self):
return reverse('bookshelf:book_details', kwargs={'pk': self.pk})
{% extends 'base.html' %}
{% load static %}
{% block title %} My Favorite Authors{% endblock %}
{% block content %}
<h1>Rafa's Favorite Authors:</h1>
<ul>
{% for author in author_list %}
<li>
<a href="{{author.get_absolute_url}}">
{{ author.first_name }} {{ author.last_name }}
</a>
</li>
{% endfor %}
</ul>
{% endblock %}
{% block footer %}<a href="/home">Home</a> -- <a href="/books">Books</a>{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block title %} {{ author.first_name }} {{ author.last_name }} {% endblock %}
{% block content %}
<h1>{{ author.first_name }} {{ author.last_name }}</h1>
<h3>{{ author.age }}</h3>
<h3>{{ author.nationality }}</h3>
<h3>{{ author.bio }}</h3>
<br>
<h2> Books by {{ author.first_name }} {{ author.last_name }} I love:</h2>
<ul>
{% for book in author.books_set.all %}
<li>
<a href="{{ books.get_absolute_url }}">{{ book.title }}</a>
</li>
{% endfor %}
</ul>
{% endblock %}
{% block footer %}<a href="/home">Home</a> -- <a href="/books">Books</a> -- <a href="/author">Authors</a>{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block title %} My Favorite Books{% endblock %}
{% block content %}
<h1>Rafa's Favorite Books:</h1>
<ul>
{% for book in books_list %}
<li>
<a href="{{ books.get_absolute_url}}">
{{ books.title }}
</a>
</li>
{% endfor %}
</ul>
{% endblock %}
{% block footer %}<a href="/home">Home</a> -- <a href="/author">Authors</a>{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block title %} {{ books.title }} {% endblock %}
{% block content %}
<h1>{{ books.title }}</h1>
<h2><a href="{{ books.author.get_absolute_url }}">{{ books.author.first_name }} {{ books.author.last_name }}</a></h2>
<h3>{{ books.publisher }}</h3>
<h3>{{ books.year_published }}</h3>
<h3>{{ books.ISBN }}</h3>
<p>{{ books.blurb }}</p>
{% endblock %}
{% block footer %}<a href="/home">Home</a> -- <a href="/books">Books</a> -- <a href="/author">Authors</a>{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block title %} My Favorite Books And Authors {% endblock %}
{% block content %}
<h2>Welcome to Rafa's Database of Favorite Books and Authors!</h2>
<br>
<p>Not gonna lie, I don't really enjoy reading. Books makes me sleepy...
So, the books that I do enjoy are exceptionally good! Take my word for it. </p>
{% endblock %}
{% block footer %}<a href="/books">Books</a> -- <a href="/author">Authors</a>{% endblock %}
\ No newline at end of file
from django.urls import path
from .views import (
BooksView, PerBooksView,
AuthorView, PerAuthorView,
)
urlpatterns = [
path('books', BooksView.as_view(), name='books'),
path('books<int:pk>/details', PerBooksView.as_view(), name='book_details'),
path('author', AuthorView.as_view(), name='author'),
path('author<int:pk>/details', PerAuthorView.as_view(), name='author_details'),
]
app_name = 'bookshelf'
from django.shortcuts import render
from .models import Author, Books
from django.views.generic.list import ListView
from django.views.generic.detail import DetailView
def home(request):
return render(request, 'bookshelf/home.html')
class BooksView(ListView):
model = Books
template_name = 'books.html'
class PerBooksView(DetailView):
model = Books
template_name = 'books_details.html'
class AuthorView(ListView):
model = Author
template_name = 'author.html'
class PerAuthorView(DetailView):
model = Author
template_name = 'author_details.html'
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