Commit 3b6e90c5 authored by Colleen's avatar Colleen

added and modified templates

parent 558df3aa
Pipeline #3111 canceled with stages
from django.db import models
from django.urls import reverse
class Author(models.Model):
first_name = models.CharField(max_length=100)
......@@ -7,8 +8,11 @@ class Author(models.Model):
nationality = models.CharField(max_length=100)
bio = models.CharField(max_length=700)
def _self_(self):
return self.first_name
def __str__(self):
return '{} {}'.format(self.first_name, self.last_name)
def get_absolute_url(self):
return reverse('bookshelf:authors-detail', kwargs={'pk': self.pk})
class Books(models.Model):
title = models.CharField(max_length=100)
......@@ -17,3 +21,6 @@ class Books(models.Model):
year_published = models.IntegerField()
ISBN = models.IntegerField()
blurb = models.CharField(max_length=200)
def get_absolute_url(self):
return reverse('bookshelf:books-detail', kwargs={'pk': self.pk})
\ No newline at end of file
{%extends 'base.html'%}
{% block content %}
<h1>{{object.last_name}}</h1>
<h2>{{object.age}}</h2>
<h2>{{object.nationality}}</h2>
<h2>{{object.bio}}</h2>
<ul>
<li>
<a href="/bookshelf"> home
</a>
</li>
</ul>
<ul>
<li>
<a href="/bookshelf/books"> books
</a>
</li>
</ul>
<ul>
<li>
<a href="/bookshelf/authors"> authors
</a>
</li>
</ul>
{% endblock %}
\ No newline at end of file
{%extends 'base.html'%}
{% block content %}
<h1>Colleen's favorite Authors:</h1>
<ul>
{% for object in object_list %}
<li>
<a href="{{ object.get_absolute_url }}">
{{object.last_name}}
</a>
</li>
{% endfor %}
</ul>
<ul>
<li>
<a href="/bookshelf"> home
</a>
</li>
</ul>
<ul>
<li>
<a href="/bookshelf/books"> books
</a>
</li>
</ul>
{% endblock %}
\ No newline at end of file
{%extends 'base.html'%}
{% block content %}
<h1>{{object.title}}</h1>
<h2>{{object.author}}</h2>
<h2>{{object.publisher}}</h2>
<h2>{{object.year_published}}</h2>
<h2>{{object.ISBN}}</h2>
<h2>{{object.blurb}}</h2>
<ul>
<li>
<a href="/bookshelf"> home
</a>
</li>
</ul>
<ul>
<li>
<a href="/bookshelf/books"> books
</a>
</li>
</ul>
<ul>
<li>
<a href="/bookshelf/authors"> authors
</a>
</li>
</ul>
{% endblock %}
\ No newline at end of file
{%extends 'base.html'%}
{% block content %}
<h1>Colleen's favorite Books:</h1>
<ul>
{% for object in object_list %}
<li>
<a href="{{ object.get_absolute_url }}">
{{object.title}}
</a>
</li>
{% endfor %}
</ul>
<ul>
<li>
<a href="/bookshelf"> home
</a>
</li>
</ul>
<ul>
<li>
<a href="/bookshelf/authors"> authors
</a>
</li>
</ul>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block title %}My Favorite Books & Authors{% endblock %}
{% block content %}
<title>My Favorite Books & Authors</title>
<h1>Welcome to Colleen's Database of Favorite Books and Authors!</h1>
<h2>This database contains a diverse variety of genres. Most of these are well-known and beloved by the majority.</h2>
<ul>
<li>
<a href="/bookshelf/books"> books
</a>
</li>
</ul>
<ul>
<li>
<a href="/bookshelf/authors"> authors
</a>
</li>
</ul>
{% endblock %}
\ No newline at end of file
from django.urls import path
from .views import index
from .views import HomepageView,BooksListView,BooksDetailView,AuthorListView,AuthorDetailView
urlpatterns = [
path('', index, name='index'),
path('', HomepageView, name='homeview'),
path('books', BooksListView.as_view(), name='books-list'),
path('books/<int:pk>', BooksDetailView.as_view(), name='books-detail'),
path('authors', AuthorListView.as_view(), name='authors-list'),
path('authors/<int:pk>', AuthorDetailView.as_view(), name='authors-detail'),
]
app_name = "bookshelf"
\ No newline at end of file
from django.http import HttpResponse
from django.views import View
from django.views.generic.detail import DetailView
from django.views.generic.list import ListView
from django.shortcuts import render
from .models import Author, Books
def HomepageView(request):
return render(request, 'bookshelf/home.html', {'name':'Ian'})
class BooksListView(ListView):
model = Books
class BooksDetailView(DetailView):
model = Books
class AuthorListView(ListView):
model = Author
class AuthorDetailView(DetailView):
model = Author
def index(request):
return HttpResponse('Hello World! This came from the index view')
\ No newline at end of file
......@@ -58,7 +58,7 @@ ROOT_URLCONF = 'colleengarcia_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 path, include
urlpatterns = [
path('bookshelf', include('bookshelf.urls', namespace="bookshelf")),
path('bookshelf/', include('bookshelf.urls', namespace="bookshelf")),
path('admin/', admin.site.urls),
]
No preview for this file type
<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
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