Commit a434192c authored by Sharmaine Chua's avatar Sharmaine Chua

added templates and edited the views, urls

parent fe433cfb
Pipeline #3089 failed with stages
from django.db import models
from django.core.exceptions import ValidationError
from django.urls import reverse
def validate_isbn(input):
if len(str(input)) != 13:
......@@ -15,6 +16,10 @@ class Author(models.Model):
def __str__(self):
return '{} {}'.format(self.first_name, self.last_name)
def get_absolute_url(self):
return reverse('bookshelf:author_details', kwargs={'pk': self.pk})
class Books(models.Model):
title = models.CharField(max_length=50,default="")
author = models.ForeignKey(Author,on_delete=models.CASCADE)
......@@ -26,3 +31,6 @@ class Books(models.Model):
def __str__(self):
return '{} by {} {}'.format(self.title, self.author.first_name, self.author.last_name)
def get_absolute_url(self):
return reverse('bookshelf:book_details', kwargs={'pk': self.pk})
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block title %} {{ object.title }} {% endblock %}
{% block content %}
<h1>{{ object }}</h1>
<h3>
Age: {{ object.age }} years old <br>
Nationality: {{ object.nationality }} <br>
Bio: <br>
{{ object.bio }} <br> <br>
Books by {{ object }} I love: <br>
{% for books in object.books_set.all %}
<a href="{{ books.get_absolute_url }}">
<li>
{{ books.title }}, {{ books.year_published }}
</li>
</a>
{% endfor %}
</h3>
{# the links to other html files #}
<center>
<a href="../../home">
<button type="button">Home</button>
</a>
<a href="../../books">
<button type="button">Books</button>
</a>
<a href="../../authors">
<button type="button">Authors</button>
</a>
</center>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block content %}
<h1>Sharm's Favorite Authors:</h1>
{% for object in object_list %}
<a href="{{ object.get_absolute_url }}">
<li>
{{ object }}
</li>
</a>
{% endfor %}
<br><br><br>
{# the links to other html files #}
<center>
<a href="../home">
<button type="button">Home</button>
</a>
<a href="../books">
<button type="button">Books</button>
</a>
</center>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block title %} {{ object.title }} {% endblock %}
{% block content %}
<h1>{{ object.title }}</h1>
<h3>
by
<a href = {{ object.author.get_absolute_url }}>
{{ object.author }}
</a>
<br>
Publisher: {{ object.publisher }} <br>
Year Published: {{ object.year_published }} <br>
ISBN: {{ object.ISBN }} <br>
Blurb: {{ object.blurb }} <br>
</h3>
{# the links to other html files #}
<center>
<a href="../../home">
<button type="button">Home</button>
</a>
<a href="../../books">
<button type="button">Books</button>
</a>
<a href="../../authors">
<button type="button">Authors</button>
</a>
</center>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block styles %}
<style>
background-color: #afcaff";
</style>
{% endblock %}
{% block content %}
<h1>Sharm's Favorite Books:</h1>
{% for object in object_list %}
<a href="{{ object.get_absolute_url }}">
<li>
{{ object.title }}
</li>
</a>
{% endfor %}
<br><br><br>
{# the links to other html files #}
<center>
<a href="../home">
<button type="button">Home</button>
</a>
<a href="../authors">
<button type="button">Authors</button>
</a>
</center>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block content %}
<center>
<h1>Welcome to Sharm's Database of Favorite Books and Authors!</h1>
<h3>I like to read romance books to romanticize my life. (this is why im marupok) <br>
Also the books here are not the books I have read because I forgot their titles... <br>
im sorry...<br></h3>
<br><br><br><br><br>
{# the links to other html files #}
<a href="../books">
<button type="button">Books</button>
</a>
<a href="../authors">
<button type="button">Authors</button>
</a>
</center>
{% endblock %}
\ No newline at end of file
from django.urls import path
from .views import index
from .views import *
urlpatterns = [
path('',index,name='index')
path('home/',index,name='home'),
path('books/',BooksListView.as_view(),name='books_list'),
path('books/<int:pk>/details',BooksDetailView.as_view(),name='book_details'),
path('authors/',AuthorListView.as_view(),name='author_list'),
path('authors/<int:pk>/details',AuthorDetailView.as_view(),name='author_details'),
]
app_name = 'bookshelf'
\ No newline at end of file
from django.shortcuts import render
from django.http import HttpResponse, request
from django.views import View
from .models import Author, Books
from django.views.generic.list import ListView
from django.views.generic.detail import DetailView
from django.http import HttpResponse
def index(request):
return HttpResponse('This is the bookshelf!')
return render(request, 'bookshelf/home.html',)
class BooksListView(ListView):
model = Books
template_name='bookshelf/books.html'
class BooksDetailView(DetailView):
model = Books
template_name='bookshelf/book_details.html'
class AuthorListView(ListView):
model = Author
template_name='bookshelf/authors.html'
class AuthorDetailView(DetailView):
model = Author
template_name='bookshelf/author_details.html'
\ No newline at end of file
......@@ -59,7 +59,7 @@ ROOT_URLCONF = 'sharmchua_reading.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'DIRS': [os.path.join(BASE_DIR, 'templates')],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
......@@ -123,6 +123,7 @@ USE_TZ = True
# https://docs.djangoproject.com/en/3.2/howto/static-files/
STATIC_URL = '/static/'
STATICFILES_DIRS = [os.path.join(BASE_DIR, 'static')]
# Default primary key field type
# https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field
......
......@@ -17,6 +17,6 @@ from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('bookshelf/', include('bookshelf.urls', namespace="bookshelf")),
path('bookshelf/', include('bookshelf.urls')),
path('admin/', admin.site.urls),
]
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" href="style.css">
<title>{% block title %}My Favorite Books and Authors{% endblock %}</title>
</head>
<body>
<div id="content">
{% block content %}{% endblock %}
</div>
</body>
</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