Update bookshelf models, create templates

Data populated in books, added get_absolute_url for bookshelf models, created templates for app
parent c6f06264
...@@ -12,10 +12,13 @@ class Author(models.Model): ...@@ -12,10 +12,13 @@ class Author(models.Model):
def __str__(self): def __str__(self):
return '{} {}'.format(self.first_name, self.last_name) return '{} {}'.format(self.first_name, self.last_name)
def get_absolute_url(self):
return f"{self.pk}"
class Books(models.Model): class Books(models.Model):
title = models.CharField(max_length=255) title = models.CharField(max_length=255)
author = models.ForeignKey(Author, on_delete=models.CASCADE) author = models.ForeignKey(Author, on_delete=models.CASCADE, related_name='books')
publisher = models.CharField(max_length=255) publisher = models.CharField(max_length=255)
year_published = models.IntegerField() year_published = models.IntegerField()
ISBN = models.CharField(max_length=13) ISBN = models.CharField(max_length=13)
...@@ -23,3 +26,6 @@ class Books(models.Model): ...@@ -23,3 +26,6 @@ class Books(models.Model):
def __str__(self): def __str__(self):
return '{}'.format(self.title) return '{}'.format(self.title)
def get_absolute_url(self):
return f"{self.pk}"
\ No newline at end of file
<!DOCTYPE html>
<html lang="en">
<head>
<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 %} My Favorite Books & Authors {% endblock %}
{% block content %}
<h1> Welcome to {{ name }}'s Database of Favorite Books and Authors!</h1>
<br>
<h3> Throughout high school, reading books became one of my hobbies
whenever I was bored. I usually enjoy young adult adventure books
back then which is why I became obsessed with Rick Riordan's novels.
Generally, it adventure or motivational (like Mitch Albom's) books
were my go-to when it comes to genres. Authors comes second in mind,
but I won't hesitate to stop patronizing their works the second I
find out that they have problematic views as a person. </h3>
<a href="/books">Books</a>
<a href="/authors">Authors</a>
{% endblock %}
\ No newline at end of file
from django.shortcuts import render from django.shortcuts import render
from django.http import HttpResponse
def index(request): def index(request):
return HttpResponse("Welcome to Lay's Reading Nook!") return render(request, 'home.html', {'name': 'Lay'})
\ No newline at end of file \ No newline at end of file
...@@ -59,7 +59,7 @@ ROOT_URLCONF = 'layvillanueva_reading.urls' ...@@ -59,7 +59,7 @@ ROOT_URLCONF = 'layvillanueva_reading.urls'
TEMPLATES = [ TEMPLATES = [
{ {
'BACKEND': 'django.template.backends.django.DjangoTemplates', 'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [], 'DIRS': [BASE_DIR / 'templates'],
'APP_DIRS': True, 'APP_DIRS': True,
'OPTIONS': { 'OPTIONS': {
'context_processors': [ 'context_processors': [
......
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