Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
calvincruz_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
Calvin Josh Cruz
calvincruz_reading
Commits
b8eefd3c
Commit
b8eefd3c
authored
Mar 29, 2023
by
karin-kurusu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Created "Authors Page" and "Author's Details Page"
parent
7a199934
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
68 additions
and
1 deletion
+68
-1
models.cpython-310.pyc
...cruz_reading/bookshelf/__pycache__/models.cpython-310.pyc
+0
-0
urls.cpython-310.pyc
...incruz_reading/bookshelf/__pycache__/urls.cpython-310.pyc
+0
-0
views.cpython-310.pyc
...ncruz_reading/bookshelf/__pycache__/views.cpython-310.pyc
+0
-0
models.py
calvincruz_reading/bookshelf/models.py
+2
-0
author_details.html
...reading/bookshelf/templates/bookshelf/author_details.html
+31
-0
authors.html
...incruz_reading/bookshelf/templates/bookshelf/authors.html
+21
-0
urls.py
calvincruz_reading/bookshelf/urls.py
+3
-1
views.py
calvincruz_reading/bookshelf/views.py
+11
-0
No files found.
calvincruz_reading/bookshelf/__pycache__/models.cpython-310.pyc
View file @
b8eefd3c
No preview for this file type
calvincruz_reading/bookshelf/__pycache__/urls.cpython-310.pyc
View file @
b8eefd3c
No preview for this file type
calvincruz_reading/bookshelf/__pycache__/views.cpython-310.pyc
View file @
b8eefd3c
No preview for this file type
calvincruz_reading/bookshelf/models.py
View file @
b8eefd3c
...
...
@@ -10,6 +10,8 @@ class Author(models.Model):
def
__str__
(
self
):
return
'{} {}'
.
format
(
self
.
first_name
,
self
.
last_name
)
def
get_absolute_url
(
self
):
return
reverse
(
'bookshelf:author_details'
,
args
=
[
self
.
pk
])
class
Books
(
models
.
Model
):
title
=
models
.
CharField
(
max_length
=
250
,
default
=
""
)
...
...
calvincruz_reading/bookshelf/templates/bookshelf/author_details.html
0 → 100644
View file @
b8eefd3c
{% extends 'base.html' %}
{% load static %}
{% block title %}{{author.first_name}} {{author.last_name}}{% endblock %}
{% block content %}
<h2>
{{author.first_name}} {{author.last_name}}
</h2>
<p>
{{author.first_name}} {{author.last_name}}
</p>
<p>
{{author.age}}
</p>
<p>
{{author.nationality}}
</p>
<p>
{{author.bio}}
</p>
<h2>
Books by {{author.first_name}} {{author.last_name}} I love:
</h2>
<ul>
{% for book in book_list %}
<li><a
href=
{{book.get_absolute_url}}
>
{{book.title}}
</a></li>
{% endfor %}
</ul>
{% endblock %}
{% block navbar %}
<ul
class=
"navbarList"
>
<li
class=
"navbarItem"
><a
href=
"/home"
>
Home
</a></li>
<li
class=
"navbarItem"
><a
href=
"/books"
>
Books
</a></li>
<li
class=
"navBarItem"
><a
href=
"/authors"
>
Authors
</a></li>
</ul>
{% endblock %}
\ No newline at end of file
calvincruz_reading/bookshelf/templates/bookshelf/authors.html
0 → 100644
View file @
b8eefd3c
{% extends 'base.html' %}
{% load static %}
{% block title %}My Favorite Authors{% endblock %}
{% block content %}
<h2>
{{name}}'s Favorite Authors:
</h2>
<ul>
{% for author in author_list %}
<li><a
href=
"{{author.get_absolute_url}}"
>
{{author.first_name}} {{author.last_name}}
</a></li>
{% endfor %}
</ul>
{% endblock %}
{% block navbar %}
<ul
class=
"navbarList"
>
<li
class=
"navbarItem"
><a
href=
"/home"
>
Home
</a></li>
<li
class=
"navBarItem"
><a
href=
"/books"
>
Books
</a></li>
</ul>
{% endblock %}
\ No newline at end of file
calvincruz_reading/bookshelf/urls.py
View file @
b8eefd3c
from
django.urls
import
path
from
.views
import
home
,
BooksList
,
BooksDetails
from
.views
import
home
,
BooksList
,
BooksDetails
,
AuthorList
,
AuthorDetails
urlpatterns
=
[
path
(
'home/'
,
home
,
name
=
'home'
),
path
(
'books/'
,
BooksList
.
as_view
(),
name
=
'books'
),
path
(
'books/<int:pk>/details'
,
BooksDetails
.
as_view
(),
name
=
'book_detais'
),
path
(
'authors/'
,
AuthorList
.
as_view
(),
name
=
"authors"
),
path
(
'authors/<int:pk>/details'
,
AuthorDetails
.
as_view
(),
name
=
'author_details'
),
]
app_name
=
"bookshelf"
\ No newline at end of file
calvincruz_reading/bookshelf/views.py
View file @
b8eefd3c
...
...
@@ -17,4 +17,15 @@ class BooksDetails(DetailView):
book
=
Books
.
objects
.
get
(
pk
=
pk
)
author
=
book
.
author
return
render
(
request
,
'bookshelf/book_detais.html'
,
{
'author'
:
author
,
'book'
:
book
})
class
AuthorList
(
ListView
):
def
get
(
self
,
request
):
author_list
=
Author
.
objects
.
all
()
return
render
(
request
,
'bookshelf/authors.html'
,
{
'name'
:
'Calvin'
,
'author_list'
:
author_list
})
class
AuthorDetails
(
DetailView
):
def
get
(
self
,
request
,
pk
):
author
=
Author
.
objects
.
get
(
pk
=
pk
)
book_list
=
Books
.
objects
.
filter
(
author__first_name__exact
=
author
.
first_name
)
return
render
(
request
,
'bookshelf/author_details.html'
,
{
'author'
:
author
,
'book_list'
:
book_list
})
# Create your views here.
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