Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
J
justinreyes_reading
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Justin Reyes
justinreyes_reading
Commits
03e3540e
Commit
03e3540e
authored
Mar 27, 2023
by
justin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Created detail HTML pages for each author, fixed URL routing for authors in book pages
parent
5ee8933e
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
65 additions
and
24 deletions
+65
-24
models.py
justinreyes_reading/bookshelf/models.py
+6
-0
author_details.html
...reading/bookshelf/templates/bookshelf/author_details.html
+30
-0
authors.html
...nreyes_reading/bookshelf/templates/bookshelf/authors.html
+17
-0
book_details.html
...s_reading/bookshelf/templates/bookshelf/book_details.html
+1
-1
urls.py
justinreyes_reading/bookshelf/urls.py
+5
-5
views.py
justinreyes_reading/bookshelf/views.py
+6
-18
No files found.
justinreyes_reading/bookshelf/models.py
View file @
03e3540e
...
...
@@ -18,6 +18,12 @@ class Author(models.Model):
def
__str__
(
self
):
return
f
"{self.first_name} {self.last_name}"
def
get_absolute_url
(
self
):
return
reverse
(
"author-detail"
,
kwargs
=
{
"pk"
:
self
.
pk
},
)
class
Books
(
models
.
Model
):
title
=
models
.
CharField
(
max_length
=
255
)
...
...
justinreyes_reading/bookshelf/templates/bookshelf/author_details.html
0 → 100644
View file @
03e3540e
{% extends 'base.html' %}
{% block title %} {{ object.first_name }} {{ object.last_name }} {% endblock %}
{% block content %}
<div
class=
"author-details"
>
<h1>
{{ object }}
</h1>
<ul>
<li>
{{ object.age }}
</li>
<li>
{{ object.nationality }}
</li>
<li>
{{ object.bio }}
</li>
</ul>
</div>
<div
class=
"author-books"
>
<h1>
Books by {{ object }} I love
</h1>
<ul>
{% for book in object.books_set.all %}
<a
href=
"{{book.get_absolute_url}}"
><li>
{{book.title}}
</li></a>
{% endfor %}
</ul>
</div>
<ul>
<li><a
href=
"/home"
>
Home
</a></li>
<li><a
href=
"/books"
>
Books
</a></li>
<li><a
href=
"/authors"
>
Authors
</a></li>
</ul>
{% endblock %}
justinreyes_reading/bookshelf/templates/bookshelf/authors.html
0 → 100644
View file @
03e3540e
{% extends 'base.html' %}
{% block title %} My Favorite Authors {% endblock %}
{% block content %}
<h1>
Justin' Favorite Authors
</h1>
<ul>
{% for object in object_list %}
<a
href=
"{{object.get_absolute_url}}"
><li>
{{object.first_name}} {{object.last_name}}
</li></a>
{% endfor %}
</ul>
<ul>
<li><a
href=
"/home"
>
Home
</a></li>
<li><a
href=
"/books"
>
Books
</a></li>
</ul>
{% endblock %}
justinreyes_reading/bookshelf/templates/bookshelf/book_details.html
View file @
03e3540e
...
...
@@ -6,7 +6,7 @@
<div
class=
"book-details"
>
<h1>
{{ object.title }}
</h1>
<ul>
<
li>
{{ object.author }}
</li
>
<
a
href=
"{{object.author.get_absolute_url}}"
><li>
{{ object.author }}
</li></a
>
<li>
{{ object.publisher }}
</li>
<li>
{{ object.year_published }}
</li>
<li>
{{ object.isbn }}
</li>
...
...
justinreyes_reading/bookshelf/urls.py
View file @
03e3540e
...
...
@@ -3,14 +3,14 @@ from .views import (
index
,
BookListView
,
BookDetailView
,
AuthorListView
,
AuthorDetailView
,
)
urlpatterns
=
[
path
(
"home/"
,
index
,
name
=
"home"
),
path
(
"books/"
,
BookListView
.
as_view
(),
name
=
"book-list"
,
),
path
(
"books/"
,
BookListView
.
as_view
(),
name
=
"book-list"
),
path
(
"books/<int:pk>/detail"
,
BookDetailView
.
as_view
(),
name
=
"book-detail"
),
path
(
"authors/"
,
AuthorListView
.
as_view
(),
name
=
"author-list"
),
path
(
"author/<int:pk>/detail"
,
AuthorDetailView
.
as_view
(),
name
=
"author-detail"
),
]
justinreyes_reading/bookshelf/views.py
View file @
03e3540e
...
...
@@ -12,16 +12,6 @@ def index(request):
)
def
books
(
request
):
bookList
=
Books
.
objects
.
all
()
context
=
{
"bookList"
:
bookList
}
return
render
(
request
,
"bookshelf/books.html"
,
context
,
)
class
BookListView
(
ListView
):
model
=
Books
template_name
=
"bookshelf/books.html"
...
...
@@ -32,13 +22,11 @@ class BookDetailView(DetailView):
template_name
=
"bookshelf/book_details.html"
# class BooksView(View):
# def get(self, request):
# books = Books.objects.all()
# context = {"books": books}
# return render(request, "bookshelf/books.html", context)
class
AuthorListView
(
ListView
):
model
=
Author
template_name
=
"bookshelf/authors.html"
# class HomePageView(
View):
# def get(self, request):
# return (render, "bookshelf/home.html")
class
AuthorDetailView
(
Detail
View
):
model
=
Author
template_name
=
"bookshelf/author_details.html"
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment