Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
gabgeraldo_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
Gabriel Geraldo
gabgeraldo_reading
Commits
ea8a6d44
Commit
ea8a6d44
authored
Mar 30, 2023
by
Gabriel Geraldo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added templates and views for bookshelf pages
parent
704c2091
Changes
11
Show whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
142 additions
and
8 deletions
+142
-8
models.py
gabgeraldo_reading/bookshelf/models.py
+10
-2
author_details.html
...reading/bookshelf/templates/bookshelf/author_details.html
+21
-0
authors.html
...eraldo_reading/bookshelf/templates/bookshelf/authors.html
+15
-0
book_details.html
...o_reading/bookshelf/templates/bookshelf/book_details.html
+15
-0
books.html
gabgeraldo_reading/bookshelf/templates/bookshelf/books.html
+15
-0
home.html
gabgeraldo_reading/bookshelf/templates/bookshelf/home.html
+9
-0
index.html
gabgeraldo_reading/bookshelf/templates/bookshelf/index.html
+5
-0
urls.py
gabgeraldo_reading/bookshelf/urls.py
+7
-2
views.py
gabgeraldo_reading/bookshelf/views.py
+32
-3
settings.py
gabgeraldo_reading/gabgeraldo_reading/settings.py
+1
-1
base.html
gabgeraldo_reading/templates/base.html
+12
-0
No files found.
gabgeraldo_reading/bookshelf/models.py
View file @
ea8a6d44
from
django.db
import
models
from
django.db
import
models
from
django.core.validators
import
MinValueValidator
,
MaxValueValidator
,
MinLengthValidator
,
MaxLengthValidator
from
django.core.validators
import
MinValueValidator
,
MaxValueValidator
,
MinLengthValidator
,
MaxLengthValidator
from
django.utils.timezone
import
datetime
from
django.utils.timezone
import
datetime
from
django.urls
import
reverse
# Create your models here.
# Create your models here.
class
Author
(
models
.
Model
):
class
Author
(
models
.
Model
):
...
@@ -13,9 +14,12 @@ class Author(models.Model):
...
@@ -13,9 +14,12 @@ class Author(models.Model):
def
__str__
(
self
):
def
__str__
(
self
):
return
f
"{self.first_name} {self.last_name}"
return
f
"{self.first_name} {self.last_name}"
def
get_absolute_url
(
self
):
return
reverse
(
"bookshelf:author_details"
,
kwargs
=
{
'pk'
:
self
.
pk
})
class
Books
(
models
.
Model
):
class
Books
(
models
.
Model
):
title
=
models
.
CharField
(
max_length
=
255
)
title
=
models
.
CharField
(
max_length
=
255
)
author
=
models
.
ForeignKey
(
Author
,
on_delete
=
models
.
CASCADE
)
author
=
models
.
ForeignKey
(
Author
,
on_delete
=
models
.
CASCADE
,
related_name
=
'books'
)
publisher
=
models
.
CharField
(
max_length
=
255
)
publisher
=
models
.
CharField
(
max_length
=
255
)
year_published
=
models
.
PositiveIntegerField
(
year_published
=
models
.
PositiveIntegerField
(
validators
=
[
MaxValueValidator
(
datetime
.
today
()
.
year
)]
validators
=
[
MaxValueValidator
(
datetime
.
today
()
.
year
)]
...
@@ -30,3 +34,7 @@ class Books(models.Model):
...
@@ -30,3 +34,7 @@ class Books(models.Model):
def
__str__
(
self
):
def
__str__
(
self
):
return
f
"{self.title} by {self.author}"
return
f
"{self.title} by {self.author}"
def
get_absolute_url
(
self
):
return
reverse
(
"bookshelf:book_details"
,
kwargs
=
{
'pk'
:
self
.
pk
})
gabgeraldo_reading/bookshelf/templates/bookshelf/author_details.html
0 → 100644
View file @
ea8a6d44
{% extends 'base.html' %}
{% block title %}{{ object.first_name }} {{ object.last_name }}{% endblock %}
{% block content %}
<h1>
{{ object.first_name }} {{ object.last_name }}
</h1>
<p>
{{ object.age }}
</p>
<p>
{{ object.nationality }}
</p>
<p>
{{ object.bio}}
</p>
<h1>
Books by {{ object.first_name }} {{ object.last_name }} I love
</h1>
<ul>
{% for book in object.books.all %}
<li>
<a
href=
"{{ book.get_absolute_url }}"
>
{{ book.title }}
</a>
</li>
{% endfor %}
</ul>
<a
href=
"../../home"
>
Home
</a>
<a
href=
"../../books"
>
Books
</a>
<a
href=
"../"
>
Authors
</a>
{% endblock %}
gabgeraldo_reading/bookshelf/templates/bookshelf/authors.html
0 → 100644
View file @
ea8a6d44
{% extends 'base.html' %}
{% block title %}My Favorite Authors{% endblock %}
{% block content %}
<h1>
{{ nickname }}'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>
<a
href=
"../home"
>
Home
</a>
<a
href=
"../books"
>
Books
</a>
{% endblock %}
gabgeraldo_reading/bookshelf/templates/bookshelf/book_details.html
0 → 100644
View file @
ea8a6d44
{% extends 'base.html' %}
{% block title %}{{ object.title }}{% endblock %}
{% block content %}
<h1>
{{ object.title }}
</h1>
<p>
{{ object.author }}
</p>
<p>
{{ object.publisher }}
</p>
<p>
{{ object.year_published}}
</p>
<p>
{{ object.isbn }}
</p>
<p>
{{ object.blurb }}
</p>
<a
href=
"../../home"
>
Home
</a>
<a
href=
"../"
>
Books
</a>
<a
href=
"../../authors"
>
Authors
</a>
{% endblock %}
gabgeraldo_reading/bookshelf/templates/bookshelf/books.html
0 → 100644
View file @
ea8a6d44
{% extends 'base.html' %}
{% block title %}My Favorite Books{% endblock %}
{% block content %}
<h1>
{{ nickname }}'s Favorite Books:
</h1>
<ul>
{% for object in object_list %}
<li><a
href=
"{{ object.get_absolute_url }}"
>
{{ object.title }}
</a></li>
{% endfor %}
</ul>
<a
href=
"../home"
>
Home
</a>
<a
href=
"../authors"
>
Authors
</a>
{% endblock %}
gabgeraldo_reading/bookshelf/templates/bookshelf/home.html
0 → 100644
View file @
ea8a6d44
{% extends 'base.html' %}
{% block title %}My Favorite Books
&
Authors{% endblock %}
{% block content %}
<h1>
Welcome to {{ nickname }}'s Database of Favorite Books and Authors!
</h1>
<p>
I really like etc and etc
</p>
<a
href=
"../books"
>
Books
</a>
<a
href=
"../authors"
>
Authors
</a>
{% endblock %}
gabgeraldo_reading/bookshelf/templates/bookshelf/index.html
0 → 100644
View file @
ea8a6d44
{% extends 'base.html' %}
{% block scripts %}
<meta
http-equiv=
"Refresh"
content=
"0; url='home/"
/>
{% endblock %}
\ No newline at end of file
gabgeraldo_reading/bookshelf/urls.py
View file @
ea8a6d44
from
django.urls
import
path
from
django.urls
import
path
from
.views
import
index
from
.views
import
index
_view
,
home_view
,
BooksListView
,
BooksDetailView
,
AuthorListView
,
AuthorDetailView
urlpatterns
=
[
urlpatterns
=
[
path
(
''
,
index
,
name
=
'index'
)
path
(
''
,
index_view
,
name
=
'index'
),
path
(
'home/'
,
home_view
,
name
=
'home'
),
path
(
'books/'
,
BooksListView
.
as_view
(
template_name
=
'bookshelf/books.html'
),
name
=
'books'
),
path
(
'books/<int:pk>/details'
,
BooksDetailView
.
as_view
(
template_name
=
'bookshelf/book_details.html'
),
name
=
'book_details'
),
path
(
'authors/'
,
AuthorListView
.
as_view
(
template_name
=
'bookshelf/authors.html'
),
name
=
'authors'
),
path
(
'authors/<int:pk>/details'
,
AuthorDetailView
.
as_view
(
template_name
=
'bookshelf/author_details.html'
),
name
=
'author_details'
),
]
]
app_name
=
"bookshelf"
app_name
=
"bookshelf"
\ No newline at end of file
gabgeraldo_reading/bookshelf/views.py
View file @
ea8a6d44
from
django.shortcuts
import
render
from
django.shortcuts
import
render
from
django.http
import
HttpResponse
from
django.views
import
View
from
django.views.generic.detail
import
DetailView
from
django.views.generic.list
import
ListView
from
.models
import
Books
,
Author
# Create your views here.
# Create your views here.
def
index
(
request
):
def
index_view
(
request
):
return
HttpResponse
(
'initialized bookshelf views'
)
return
render
(
request
,
"bookshelf/index.html"
,
{})
\ No newline at end of file
def
home_view
(
request
):
return
render
(
request
,
"bookshelf/home.html"
,
{
'nickname'
:
'Gab'
})
class
BooksListView
(
ListView
):
model
=
Books
def
get_context_data
(
self
,
**
kwargs
):
ctx
=
super
()
.
get_context_data
(
**
kwargs
)
ctx
[
'nickname'
]
=
'Gab'
return
ctx
class
BooksDetailView
(
DetailView
):
model
=
Books
class
AuthorListView
(
ListView
):
model
=
Author
def
get_context_data
(
self
,
**
kwargs
):
ctx
=
super
()
.
get_context_data
(
**
kwargs
)
ctx
[
'nickname'
]
=
'Gab'
return
ctx
class
AuthorDetailView
(
DetailView
):
model
=
Author
\ No newline at end of file
gabgeraldo_reading/gabgeraldo_reading/settings.py
View file @
ea8a6d44
...
@@ -59,7 +59,7 @@ ROOT_URLCONF = 'gabgeraldo_reading.urls'
...
@@ -59,7 +59,7 @@ ROOT_URLCONF = 'gabgeraldo_reading.urls'
TEMPLATES
=
[
TEMPLATES
=
[
{
{
'BACKEND'
:
'django.template.backends.django.DjangoTemplates'
,
'BACKEND'
:
'django.template.backends.django.DjangoTemplates'
,
'DIRS'
:
[],
'DIRS'
:
[
os
.
path
.
join
(
BASE_DIR
,
'templates'
)
],
'APP_DIRS'
:
True
,
'APP_DIRS'
:
True
,
'OPTIONS'
:
{
'OPTIONS'
:
{
'context_processors'
:
[
'context_processors'
:
[
...
...
gabgeraldo_reading/templates/base.html
0 → 100644
View file @
ea8a6d44
<!DOCTYPE html>
<html>
<head>
<title>
{% block title %}My amazing site{% endblock %}
</title>
</head>
<body>
<div
id=
"content"
>
{% block content %}{% endblock %}
</div>
{% block scripts %}{% endblock %}
</body>
</html>
\ No newline at end of file
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