Commit eba77f89 authored by Brendan Fausto's avatar Brendan Fausto

Modified models, created templates for books, authors, &homepage, and added...

Modified models, created templates for books, authors, &homepage, and added homepage to app urls and views
parent b8545f6c
...@@ -5,12 +5,23 @@ import datetime ...@@ -5,12 +5,23 @@ import datetime
class Books(models.Model): class Books(models.Model):
title = models.CharField(max_length=255) title = models.CharField(max_length=255)
author = models.ForeignKey('Authors', on_delete=models.PROTECT) author = models.ForeignKey('Authors', on_delete=models.PROTECT)
publisher = models.CharField(max_length=255) publisher = models.CharField(max_length=255)
year_published = models.IntegerField(validators = [MaxValueValidator(2023), MinValueValidator(1000)]) year_published = models.IntegerField(validators = [MaxValueValidator(2023), MinValueValidator(1000)])
isbn = models.CharField(max_length=13, validators = [MinLengthValidator(13)]) isbn = models.CharField(max_length=13, validators = [MinLengthValidator(13)])
blurb = models.CharField(max_length=800) blurb = models.CharField(max_length=800)
def __str__(self):
return self.title
def get_absolute_url(self):
return reverse('bookshelf:books-details', kwargs = {'pk': self.pk})
class Authors(models.Model): class Authors(models.Model):
...@@ -19,3 +30,15 @@ class Authors(models.Model): ...@@ -19,3 +30,15 @@ class Authors(models.Model):
age = models.IntegerField(validators = [MaxValueValidator(200), MinValueValidator(1)]) age = models.IntegerField(validators = [MaxValueValidator(200), MinValueValidator(1)])
nationality = models.CharField(max_length=255) nationality = models.CharField(max_length=255)
bio = models.CharField(max_length=700) bio = models.CharField(max_length=700)
def __str__(self):
author_fullname = ""
author_fullname += first_name
author_fullname += last_name
return author_fullname
def get_absolute_url(self):
return reverse ('bookshelf:authors-details', kwargs = {'pk': self.pk})
def get_absolute_url(self):
return reverse('bookshelf:books-details', kwargs={'pk': self.pk})
\ No newline at end of file
{% extends 'base.html' %}
{% block title %}
My Favorite Authors
{% endblock %}
{% block content %}
<ul>
{% for author in authors %}
<li>
<a href "{{ author.get_absolute_url }}">{{ author.first_name }} {{ author.last_name }}
</li>
{% endfor %}
</ul>
{% endblock %}
\ No newline at end of file
<!-- bookshelf/template/base.html -->
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" href="style.css">
<title>My Favorite {{ page_title }}!</title>
</head>
<body style = "background-color:#F0FFFF;">
<div id = "title">
{% block title %}
{% endblock %}
</div>
<div id = "content">
{% block scripts %}
{% endblock %}
</div>
</body>
</html>
\ No newline at end of file
{% extends 'base.html' %}
{% block title %}
My Favorite Books
{% endblock %}
{% block content %}
<ul>
{% for book in books %}
<li>
<a href "{{ book.get_absolute_url }}"> {{ book.title }}
</li>
{% endfor %}
</ul>
{% endblock %}
\ No newline at end of file
{{% extends 'base.html' %}
{% block title %}
Welcome to Brendan's favorite Books and Authors!
{% endblock %}
{% block content %}
Test blurb about books and their genres, as well as the authors behind the books here
{% endblock %}
\ No newline at end of file
# about/urls.py # about/urls.py
from django.urls import path from django.urls import path
from .views import index from .views import index, HomePageView
urlpatterns = [ urlpatterns = [
path('', index, name='index'), path('home', HomePageView.as_view(), name='index'),
] ]
app_name = "bookshelf" # for proper namespacing in urls, otherwise will result in errors app_name = "bookshelf" # for proper namespacing in urls, otherwise will result in errors
\ No newline at end of file
from django.shortcuts import render from django.shortcuts import render
from django.views import View
from django.views.generic.detail import DetailView
from django.views.generic.list import ListView
from .models import Books, Authors
class HomepageView(request):
return render(request, 'homepage.html', {'page_title': 'Books and Authors'})
# Create your views here. # Create your views here.
No preview for this file type
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