Commit 756a16e8 authored by John Riz Daniel Ramos's avatar John Riz Daniel Ramos

Created the templates and the views

In views.py
+ class: BooksListView
+ class: BooksDetailView
+ class: AuthorsListView
+ class: AuthorsDetailView

+ books.html, book_detais.html, authors.html, author_details.html
parent 200b0a1c
from django.db import models
from django.urls import reverse
class Author(models.Model):
......@@ -11,11 +12,20 @@ class Author(models.Model):
def __str__(self):
return '{} {}'.format(self.first_name, self.last_name)
def get_absolute_url(self):
return f"{self.pk}"
class Books(models.Model):
title = models.CharField(max_length=50)
author = models.ForeignKey(Author, on_delete=models.CASCADE)
author = models.ForeignKey(Author, on_delete=models.CASCADE, related_name='books')
publisher = models.CharField(max_length=50)
year_published = models.IntegerField()
ISBN = models.IntegerField()
blurb = models.TextField(max_length=1200)
\ No newline at end of file
blurb = models.TextField(max_length=1200)
def __str__(self):
return '{}'.format(self.title)
def get_absolute_url(self):
return f"{self.pk}"
from django.urls import path
from .views import index
from .views import home_view, BooksListView, BooksDetailView, AuthorsView, AuthorsDetailView
urlpatterns = [
path('', index, name='index'),
path('home/', home_view, name='home_view'),
path('books/', BooksListView.as_view(), name='books-list'),
path('books/<int:pk>/details/', BooksDetailView.as_view(), name='books-detail'),
path('authors/', AuthorsView.as_view(), name='authors-list'),
path('authors/<int:pk>/details/', AuthorsDetailView.as_view(), name='authors-detail'),
]
app_name = "<appname>"
\ No newline at end of file
app_name = "bookshelf"
\ No newline at end of file
from django.http import HttpResponse
from django.shortcuts import render
from django.views.generic.list import ListView
from django.views.generic.detail import DetailView
def index(request):
return HttpResponse('Hello World! This came from the index view')
\ No newline at end of file
from .models import Author, Books
def home_view(request):
return render(request, 'home.html', {'name': 'Daniel'})
class BooksListView(ListView):
model = Books
template_name = "bookshelf/books.html"
class BooksDetailView(DetailView):
model = Books
template_name = "bookshelf/book_detais.html"
class AuthorsView(ListView):
model = Author
template_name = "bookshelf/authors.html"
class AuthorsDetailView(DetailView):
model = Author
template_name = "bookshelf/author_details.html"
\ No newline at end of file
......@@ -59,7 +59,7 @@ ROOT_URLCONF = 'danielramos_reading.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'DIRS': [os.path.join(BASE_DIR, 'templates')],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
......
......@@ -17,6 +17,6 @@ from django.contrib import admin
from django.urls import include, path
urlpatterns = [
path('bookshelf/', include('bookshelf.urls', namespace="bookshelf")),
path('', include('bookshelf.urls', namespace="bookshelf")),
path('admin/', admin.site.urls),
]
<html lang="en">
<head>
<link rel="stylesheet" href="style.css">
<title>{% block title %}{% 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.first_name}} {{ object.last_name}}{% endblock %}
{% block content %}
<h1>{{ object.first_name}} {{ object.last_name}}</h1>
<p>
Age: {{ object.age }}<br>
Nationality: {{ object.nationality }}<br><br>
<i>{{ object.bio }}</i>
</p>
<h2>Books by {{ object.first_name}} {{ object.last_name}} I love:</h2>
{% for book in object.books.all %}
<li>
<a href="/books/{{ book.get_absolute_url }}/details/"> {{ book.title }}</a>
</li>
{% endfor %}
<br>
<br>
<br>
<a href="/home">Home</a>
<a href="/books">Books</a>
<a href="/authors">Authors</a>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block title %}My Favorite Authors{% endblock %}
{% block content %}
<h1>Daniel's Favorite Authors:</h1>
<ul>
{% for object in object_list %}
<li>
<a href="{{ object.get_absolute_url }}/details/">{{ object.first_name }} {{ object.last_name }}</a>
</li>
{% endfor %}
</ul>
<a href="/home">Home</a>
<a href="/authors">Authors</a>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block title %}{{ object.title }}{% endblock %}
{% block content %}
<h1>{{ object.title }}</h1>
<p>
by <a href="/authors/{{ object.author.get_absolute_url }}/details/">{{ object.author }}</a><br>
Publisher: {{ object.publisher }}<br>
Published: {{ object.year_published }}<br>
ISBN: {{ object.ISBN }}<br><br>
<i>{{ object.blurb }}</i>
</p>
<br>
<br>
<br>
<a href="/home">Home</a>
<a href="/books">Books</a>
<a href="/authors">Authors</a>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block title %}My Favorite Books{% endblock %}
{% block content %}
<h1>Daniel's Favorite Books:</h1>
<ul>
{% for object in object_list %}
<li>
<a href="{{ object.get_absolute_url }}/details/">{{ object.title }}</a>
</li>
{% endfor %}
</ul>
<a href="/home">Home</a>
<a href="/authors">Authors</a>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block title %}My Favorite Books and Authors{% endblock %}
{% block content %}
<h1>Welcome to {{ name }}'s Database of Favorite Books and Authors!</h1>
<p>I haven't read a single novel in my life under my own volition. I do not like to read, I have read none of the books that are present in the database. I have watched videos on why I should read them though. So with that in mind, I also don't have a favorite genre or author. If this database were a literary genre it would be classified as fiction.</p>
<a href="/books">Books</a>
<a href="/authors">Authors</a>
{% endblock %}
\ 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