Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
alvaalvarez_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
Angelo Alvarez
alvaalvarez_reading
Commits
c57d3ce5
Commit
c57d3ce5
authored
Mar 27, 2023
by
Angelo Alvarez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added Views and Templates for the Model Author
parent
be6c8b2a
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
77 additions
and
15 deletions
+77
-15
models.cpython-310.pyc
...arez_reading/bookshelf/__pycache__/models.cpython-310.pyc
+0
-0
urls.cpython-310.pyc
...lvarez_reading/bookshelf/__pycache__/urls.cpython-310.pyc
+0
-0
views.cpython-310.pyc
...varez_reading/bookshelf/__pycache__/views.cpython-310.pyc
+0
-0
models.py
alvaalvarez_reading/bookshelf/models.py
+3
-0
author_detail.html
..._reading/bookshelf/templates/bookshelf/author_detail.html
+29
-0
author_list.html
...ez_reading/bookshelf/templates/bookshelf/author_list.html
+21
-0
books_detail.html
...z_reading/bookshelf/templates/bookshelf/books_detail.html
+7
-7
books_list.html
...rez_reading/bookshelf/templates/bookshelf/books_list.html
+2
-2
urls.py
alvaalvarez_reading/bookshelf/urls.py
+4
-2
views.py
alvaalvarez_reading/bookshelf/views.py
+11
-4
No files found.
alvaalvarez_reading/bookshelf/__pycache__/models.cpython-310.pyc
View file @
c57d3ce5
No preview for this file type
alvaalvarez_reading/bookshelf/__pycache__/urls.cpython-310.pyc
View file @
c57d3ce5
No preview for this file type
alvaalvarez_reading/bookshelf/__pycache__/views.cpython-310.pyc
View file @
c57d3ce5
No preview for this file type
alvaalvarez_reading/bookshelf/models.py
View file @
c57d3ce5
...
...
@@ -12,6 +12,9 @@ class Author(models.Model):
def
__str__
(
self
):
return
self
.
first_name
+
" "
+
self
.
last_name
def
get_absolute_url
(
self
):
return
reverse
(
'bookshelf:authors-details'
,
kwargs
=
{
'pk'
:
self
.
pk
})
class
Books
(
models
.
Model
):
title
=
models
.
CharField
(
max_length
=
50
)
author
=
models
.
ForeignKey
(
Author
,
on_delete
=
models
.
CASCADE
)
...
...
alvaalvarez_reading/bookshelf/templates/bookshelf/author_detail.html
0 → 100644
View file @
c57d3ce5
{% extends 'base.html' %}
{% load static %}
{% block title %}{{ object.first_name }} {{ object.last_name }}{% endblock %}
{% block content %}
<h1>
{{ object.first_name }} {{ object.last_name }}
</h1>
<b>
Age:
</b>
{{ object.age }}
<br>
<b>
Nationality:
</b>
{{ object.nationality }}
<br>
{{ object.bio }}
<hr>
Books by {{ object.first_name }} {{ object.last_name }} I love:
<ul>
{% for book in books %}
{% if book.author.first_name == object.first_name and book.author.last_name == object.last_name %}
<li><a
href=
"{{ book.get_absolute_url }}"
>
{{ book.title }}
</a></li>
{% endif %}
{% endfor %}
</ul>
<div
id=
"links"
style=
"margin: auto; text-align: center; width: 100%"
>
<a
href=
"/bookshelf/home/"
>
Home
</a>
<a
href=
"/bookshelf/books/"
>
Books
</a>
<a
href=
"/bookshelf/authors/"
>
Authors
</a>
</div>
{% endblock %}
alvaalvarez_reading/bookshelf/templates/bookshelf/author_list.html
0 → 100644
View file @
c57d3ce5
{% extends 'base.html' %}
{% load static %}
{% block title %}My Favorite Authors{% endblock %}
{% block content %}
<h1>
Alva's Favorite Authors
</h1>
<ul>
{% for object in object_list %}
<li><a
href=
"{{ object.get_absolute_url }}"
>
{{ object.first_name }} {{ object.last_name }}
</a></li>
{% endfor %}
</ul>
<hr>
<div
id=
"links"
style=
"margin: auto; text-align: center; width: 100%"
>
<a
href=
"/bookshelf/home/"
>
Home
</a>
<a
href=
"/bookshelf/authors/"
>
Authors
</a>
</div>
{% endblock %}
alvaalvarez_reading/bookshelf/templates/bookshelf/books_detail.html
View file @
c57d3ce5
...
...
@@ -4,19 +4,19 @@
{% block title %}{{ object.title }}{% endblock %}
{% block content %}
<h1>
{{ object.title }}
</h1>
<
em>
Author:
</em
><a
href=
"{{ object.author.get_absolute_url }}"
>
{{ object.author }}
</a>
<br>
<
em>
Publisher:
</em
>
{{ object.publisher }}
<br>
<
em>
year_published:
</em
>
{{ object.year_published }}
<br>
<
em>
ISBN:
</em
>
{{ object.ISBN }}
<br>
<
b>
Author:
</b
><a
href=
"{{ object.author.get_absolute_url }}"
>
{{ object.author }}
</a>
<br>
<
b>
Publisher:
</b
>
{{ object.publisher }}
<br>
<
b>
Year published:
</b
>
{{ object.year_published }}
<br>
<
b>
ISBN:
</b
>
{{ object.ISBN }}
<br>
{{ object.blurb }}
<hr>
<div
id=
"links"
style=
"margin: auto; text-align: center; width: 100%"
>
<a
href=
"
..
/home/"
>
Home
</a>
<a
href=
"
/bookshelf
/home/"
>
Home
</a>
<a
href=
"
..
/books/"
>
Books
</a>
<a
href=
"
/bookshelf
/books/"
>
Books
</a>
<a
href=
"
..
/authors/"
>
Authors
</a>
<a
href=
"
/bookshelf
/authors/"
>
Authors
</a>
</div>
{% endblock %}
alvaalvarez_reading/bookshelf/templates/bookshelf/books_list.html
View file @
c57d3ce5
...
...
@@ -13,9 +13,9 @@
<hr>
<div
id=
"links"
style=
"margin: auto; text-align: center; width: 100%"
>
<a
href=
"
..
/home/"
>
Home
</a>
<a
href=
"
/bookshelf
/home/"
>
Home
</a>
<a
href=
"
..
/authors/"
>
Authors
</a>
<a
href=
"
/bookshelf
/authors/"
>
Authors
</a>
</div>
{% endblock %}
alvaalvarez_reading/bookshelf/urls.py
View file @
c57d3ce5
from
django.urls
import
path
from
.views
import
home
,
BooksListView
,
BooksDetailView
from
.views
import
home
,
BooksListView
,
BooksDetailView
,
AuthorListView
,
AuthorDetailView
urlpatterns
=
[
path
(
'home/'
,
home
,
name
=
'home'
),
path
(
'books/'
,
BooksListView
.
as_view
(),
name
=
'books-list'
),
path
(
'books/<int:pk>/details/'
,
BooksDetailView
.
as_view
(),
name
=
'books-details'
)
path
(
'books/<int:pk>/details/'
,
BooksDetailView
.
as_view
(),
name
=
'books-details'
),
path
(
'authors/'
,
AuthorListView
.
as_view
(),
name
=
'authors-list'
),
path
(
'authors/<int:pk>/details/'
,
AuthorDetailView
.
as_view
(),
name
=
'authors-details'
)
]
# This might be needed, depending on your Django version
...
...
alvaalvarez_reading/bookshelf/views.py
View file @
c57d3ce5
...
...
@@ -3,15 +3,22 @@ from django.views import View
from
django.views.generic.detail
import
DetailView
from
django.views.generic.list
import
ListView
from
.models
import
Books
from
.models
import
Books
,
Author
# Create your views here.
def
home
(
request
):
return
render
(
request
,
'home.html'
)
return
render
(
request
,
'
bookshelf/
home.html'
)
class
BooksListView
(
ListView
):
model
=
Books
class
BooksDetailView
(
DetailView
):
model
=
Books
\ No newline at end of file
model
=
Books
class
AuthorListView
(
ListView
):
model
=
Author
class
AuthorDetailView
(
DetailView
):
model
=
Author
booklist
=
Books
.
objects
.
all
()
extra_context
=
{
'books'
:
booklist
}
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