Commit 13cf5257 authored by Brendan Fausto's avatar Brendan Fausto

Added detail templates and attached respective models to templates

parent d5a8f210
from django.db import models from django.db import models
from django.core.validators import MaxValueValidator, MinValueValidator, MinLengthValidator from django.core.validators import MaxValueValidator, MinValueValidator, MinLengthValidator
from django.urls import reverse
import datetime import datetime
class Books(models.Model): class Books(models.Model):
...@@ -33,8 +34,7 @@ class Authors(models.Model): ...@@ -33,8 +34,7 @@ class Authors(models.Model):
def __str__(self): def __str__(self):
author_fullname = "" author_fullname = ""
author_fullname += first_name author_fullname += self.first_name + " " + self.last_name
author_fullname += last_name
return author_fullname return author_fullname
def get_absolute_url(self): def get_absolute_url(self):
......
{% extends 'base.html' %}
{% block title %}
{{ object.__str() }}
{% endblock %}
{% block content %}
<h1>{{ object.__str() }}</h1>
<br>
<ul>
<li>Age: {{ object.age }}</li>
<li>Nationality: {{ object.nationality }}</li>
<br>
<li>{{ object.bio }}</li>
</ul>
<br>
{% endblock %}
\ No newline at end of file
...@@ -8,9 +8,9 @@ ...@@ -8,9 +8,9 @@
{% block content %} {% block content %}
<ul> <ul>
{% for author in authors %} {% for object in authors %}
<li> <li>
<a href "{{ author.get_absolute_url }}">{{ author.first_name }} {{ author.last_name }} <a href "{{ object.get_absolute_url }}">{{ object.first_name }} {{ object.last_name }}
</li> </li>
{% endfor %} {% endfor %}
</ul> </ul>
......
{% extends 'base.html' %}
{% block title %}
{{ object.title }}
{% endblock %}
{% block content %}
<h1>{{ object.title }}</h1>
<br>
<ul>
<li>Author: <a href="{{ object.author.get_absolute_url }}""> {{ object.author }}</a></li>
<li>Publisher: {{ object.publisher }}</li>
<li>Year Published: {{ object.year_published }}</li>
<li>ISBN: {{ object.isbn }}</li>
<br>
<li>Blurb: {{ object.blurb ]}</li>
</ul>
{% endblock %}
\ No newline at end of file
...@@ -8,9 +8,9 @@ ...@@ -8,9 +8,9 @@
{% block content %} {% block content %}
<ul> <ul>
{% for book in books %} {% for object in books %}
<li> <li>
<a href "{{ book.get_absolute_url }}"> {{ book.title }} <a href "{{ object.get_absolute_url }}"> {{ object.title }}
</li> </li>
{% endfor %} {% endfor %}
</ul> </ul>
......
...@@ -9,6 +9,6 @@ ...@@ -9,6 +9,6 @@
{% block content %} {% block content %}
<p>Test blurb about books and their genres, as well as the authors behind the books here</p> <p>Test blurb about books and their genres, as well as the authors behind the books here</p>
<br> <br>
<a href = "http://127.0.0.1:8000/bookshelf/books">Books</a> <a href = "http://127.0.0.1:8000/books">Books</a>
<a href = "http://127.0.0.1:8000/bookshelf/authors">Authors</a> <a href = "http://127.0.0.1:8000/authors">Authors</a>
{% endblock %} {% 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 (home_view) from .views import (home_view, AuthorListView, BookListView, BookDetailView, AuthorDetailView)
urlpatterns = [ urlpatterns = [
path('home', home_view, name='index') path('home', home_view, name='index'),
path('books', BookListView.as_view(), name='book-list'),
path('authors', AuthorListView.as_view(), name='author-list'),
path('books/<int:pk>', BookDetailView.as_view(), name='books-details'),
path('authors/<int:pk>', AuthorDetailView.as_view(), name='authors-details'),
] ]
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
...@@ -10,4 +10,31 @@ def home_view(request): ...@@ -10,4 +10,31 @@ def home_view(request):
'page_title': "Books and Authors" 'page_title': "Books and Authors"
}) })
class AuthorListView(ListView):
def get(self, request):
authors = Authors.objects.all()
return render(request, 'bookshelf/authors_page.html', {
'authors': authors
})
class BookListView(ListView):
def get(self, request):
books = Books.objects.all()
return render(request, 'bookshelf/books_page.html', {
'books': books
})
class BookDetailView(DetailView):
model = Books
template_name = 'bookshelf/books_details.html'
class AuthorDetailView(DetailView):
model = Authors
template_name = 'bookshelf/authors_details.html'
"""
def get_context_data(self, **kwargs):
context = super(BookDetailView, self).get_context_data(**kwargs)
context[books_authored] = Books.objects.filter(author=self.object)
return context
"""
# Create your views here. # Create your views here.
No preview for this file type
...@@ -17,7 +17,7 @@ from django.contrib import admin ...@@ -17,7 +17,7 @@ from django.contrib import admin
from django.urls import include, path from django.urls import include, path
urlpatterns = [ urlpatterns = [
path('bookshelf/', include('bookshelf.urls', namespace="bookshelf")), path('', include('bookshelf.urls', namespace="bookshelf")),
path('admin/', admin.site.urls), path('admin/', admin.site.urls),
] ]
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