Templates have been created

parent 24af37ee
from django.db import models
from django.urls import reverse
# Create your models here.
class Author(models.Model):
......@@ -11,6 +12,9 @@ class Author(models.Model):
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=1000)
author = models.ForeignKey(
......@@ -24,3 +28,6 @@ class Books(models.Model):
def __str__(self):
return '{}'.format(self.title)
def get_absolute_url(self):
return reverse('bookshelf:books-detail', kwargs={'pk': self.pk})
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block title %} My Favorite Authors {% endblock %}
{% block content %}
<h1>Luigi's Favorite Authors: </h1>
<ul>
{% for object in authors %}
<li>
<a href="{{ object.get_absolute_url }}">{{ object }}</a>
</li>
{% endfor %}
</ul>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block title %} {{ object.first_name }}{% endblock %}
{% block content %}
<h1>{{ object.first_name }} {{object.last_name}}</h1>
<ul>
<li>{{ object.age }}</li>
<li>{{ object.nationality }}</li>
<li>{{ object.bio }}</li>
</ul>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block title %} {{ object.title }}{% endblock %}
{% block content %}
<h1>{{ object.title }}</h1>
<ul>
<li>{{ object.author }}</li>
<li>{{ object.publisher }}</li>
<li>{{ object.year_published }}</li>
<li>{{ object.ISBN }}</li>
<li>{{ object.blurb }}</li>
</ul>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block title %} My Favorite Books {% endblock %}
{% block content %}
<h1>Luigi's Favorite Books</h1>
<ul>
{% for object in books %}
<li>
<a href="{{ object.get_absolute_url }}">{{ object.title }}</a>
</li>
{% endfor %}
</ul>
{% 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 Luigi's Database of Favorite Books and Authors!</h1>
<p>
I don't usually read in my freetime, but when I do, I usually
<br>read mystery or coming of age novels. John Green is an author
<br>that appeals to me.
</p>
<br>
<a href="http://127.0.0.1:8000/bookshelf/books">Books</a>
{% endblock %}
\ No newline at end of file
from django.urls import path
from .views import index
from .views import (home_view,
BooksListView, BooksDetailView,
AuthorsListView, AuthorsDetailView
)
urlpatterns = [
path('', index, name='index')
path('home', home_view, name='index'),
path('books', BooksListView.as_view(), name='books-list'),
path('books/<int:pk>', BooksDetailView.as_view(), name='books-detail'),
path('authors', AuthorsListView.as_view(), name='authors-list'),
path('authors/<int:pk>', AuthorsDetailView.as_view(), name='authors-detail')
]
app_name = "bookshelf"
\ No newline at end of file
from django.shortcuts import render
from django.http import HttpResponse
from django.views import View
from django.views.generic.list import ListView
from django.views.generic.detail import DetailView
from .models import Author, Books
# Create your views here.
def index(request):
return HttpResponse("Hello World!")
\ No newline at end of file
def home_view(request):
return render(request, 'bookshelf/home.html')
class AuthorsListView(ListView):
def get(self, request):
authors = Author.objects.all()
return render(request, 'bookshelf/authors.html', {
'authors': authors
})
class AuthorsDetailView(DetailView):
models = Author
class BooksListView(ListView):
def get(self, request):
books = Books.objects.all()
return render(request, 'bookshelf/books.html', {
'books': books
})
class BooksDetailView(DetailView):
models = Books
\ No newline at end of file
......@@ -58,7 +58,7 @@ ROOT_URLCONF = 'luigirodriguez_reading.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'DIRS': [os.path.join(BASE_DIR, 'template')],
'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('bookshelf/', include('bookshelf.urls', namespace="bookshelf")),
path('admin/', admin.site.urls),
]
<!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
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