Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
nicsdevega_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
Nics De Vega
nicsdevega_reading
Commits
713e190e
Commit
713e190e
authored
Mar 28, 2023
by
Nics De Vega
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added template views and urls, minor fixes in bookshelf models
parent
6dbbe2d7
Changes
12
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
136 additions
and
9 deletions
+136
-9
models.py
nicsdevega_reading/bookshelf/models.py
+12
-2
author_details.html
...reading/bookshelf/templates/bookshelf/author_details.html
+21
-0
authors.html
...devega_reading/bookshelf/templates/bookshelf/authors.html
+15
-0
book_details.html
...a_reading/bookshelf/templates/bookshelf/book_details.html
+14
-0
books.html
nicsdevega_reading/bookshelf/templates/bookshelf/books.html
+15
-0
home.html
nicsdevega_reading/bookshelf/templates/bookshelf/home.html
+9
-0
urls.py
nicsdevega_reading/bookshelf/urls.py
+8
-3
views.py
nicsdevega_reading/bookshelf/views.py
+24
-2
settings.py
nicsdevega_reading/nicsdevega_reading/settings.py
+1
-1
urls.py
nicsdevega_reading/nicsdevega_reading/urls.py
+1
-1
base.html
nicsdevega_reading/templates/base.html
+16
-0
style.css
nicsdevega_reading/templates/style.css
+0
-0
No files found.
nicsdevega_reading/bookshelf/models.py
View file @
713e190e
from
django.db
import
models
from
django.core.validators
import
MinValueValidator
,
MaxValueValidator
,
MinLengthValidator
from
django.urls
import
reverse
class
Author
(
models
.
Model
):
first_name
=
models
.
CharField
(
max_length
=
100
,
default
=
""
)
...
...
@@ -10,14 +11,23 @@ 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"
,
kwargs
=
{
'pk'
:
self
.
pk
})
class
Book
(
models
.
Model
):
title
=
models
.
CharField
(
max_length
=
100
,
default
=
""
)
author
=
models
.
ForeignKey
(
Author
,
on_delete
=
models
.
CASCADE
)
author
=
models
.
ForeignKey
(
Author
,
on_delete
=
models
.
CASCADE
,
related_name
=
"books"
)
publisher
=
models
.
CharField
(
max_length
=
100
,
default
=
""
)
year_published
=
models
.
PositiveIntegerField
(
validators
=
[
MaxValueValidator
(
2023
)])
ISBN
=
models
.
IntegerField
(
unique
=
True
,
validators
=
[
MaxValueValidator
(
9999999999999
),
MinValueValidator
(
1000000000000
)])
blurb
=
models
.
TextField
(
validators
=
[
MinLengthValidator
(
100
)],
max_length
=
700
,
default
=
""
)
def
__str__
(
self
):
return
'{} by {}'
.
format
(
self
.
title
,
self
.
author
)
\ No newline at end of file
return
'{} by {}'
.
format
(
self
.
title
,
self
.
author
)
def
get_absolute_url
(
self
):
return
reverse
(
"bookshelf:book-details"
,
kwargs
=
{
'pk'
:
self
.
pk
})
\ No newline at end of file
nicsdevega_reading/bookshelf/templates/bookshelf/author_details.html
0 → 100644
View file @
713e190e
{% extends 'base.html' %}
{% load static %}
{% block title %}{{object.first_name}} {{object.last_name}}{% endblock %}
{% block content %}
<h3>
{{object.first_name}} {{object.last_name}}
</h3>
<h4>
{{object.age}}
</h4>
<h4>
{{object.nationality}}
</h4>
<p>
{{object.bio}}
</p>
<h3>
Books by {{object.first_name}} {{object.last_name}} I love:
</h3>
<ul>
{% for book in object.books.all %}
<li>
<a
href=
"{{ book.get_absolute_url }}"
>
{{book.title}}
</a>
</li>
{% endfor %}
</ul>
<a
href=
"/bookshelf/home/"
>
Home
</a>
<a
href=
"/bookshelf/books/"
>
Books
</a>
<a
href=
"/bookshelf/authors/"
>
Authors
</a>
{% endblock %}
\ No newline at end of file
nicsdevega_reading/bookshelf/templates/bookshelf/authors.html
0 → 100644
View file @
713e190e
{% extends 'base.html' %}
{% load static %}
{% block title %}My Favorite Authors{% endblock %}
{% block content %}
<h3>
Welcome to Nics' Favorite Authors:
</h3>
<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=
"/bookshelf/home/"
>
Home
</a>
<a
href=
"/bookshelf/books/"
>
Books
</a>
{% endblock %}
\ No newline at end of file
nicsdevega_reading/bookshelf/templates/bookshelf/book_details.html
0 → 100644
View file @
713e190e
{% extends 'base.html' %}
{% load static %}
{% block title %}{{object.title}}{% endblock %}
{% block content %}
<h3>
{{object.title}}
</h3>
<a
href =
"{{ object.author.get_absolute_url }}"
><h4>
{{object.author}}
</h4></a>
<h4>
{{object.publisher}}
</h4>
<h4>
{{object.year_published}}
</h4>
<h4>
{{object.ISBN}}
</h4>
<p>
{{object.blurb}}
</p>
<a
href=
"/bookshelf/home/"
>
Home
</a>
<a
href=
"/bookshelf/books/"
>
Books
</a>
<a
href=
"/bookshelf/authors/"
>
Authors
</a>
{% endblock %}
\ No newline at end of file
nicsdevega_reading/bookshelf/templates/bookshelf/books.html
0 → 100644
View file @
713e190e
{% extends 'base.html' %}
{% load static %}
{% block title %}My Favorite Books{% endblock %}
{% block content %}
<h3>
Welcome to Nics' Favorite Books:
</h3>
<ul>
{% for object in object_list %}
<li>
<a
href=
"{{ object.get_absolute_url }}"
>
{{object.title}}
</a>
</li>
{% endfor %}
</ul>
<a
href=
"/bookshelf/home/"
>
Home
</a>
<a
href=
"/bookshelf/authors/"
>
Authors
</a>
{% endblock %}
\ No newline at end of file
nicsdevega_reading/bookshelf/templates/bookshelf/home.html
0 → 100644
View file @
713e190e
{% extends 'base.html' %}
{% load static %}
{% block title %}My Favorite Books{% endblock %}
{% block content %}
<h2>
Welcome to Nics' Database of Favorite Books and Authors!
</h2>
<p>
I usually like books with religious themes that make me go
<b>
Insane
</b>
. I also like Revue Starlight!
</p>
<a
href=
"/bookshelf/books/"
>
Books
</a>
<a
href=
"/bookshelf/authors/"
>
Authors
</a>
{% endblock %}
\ No newline at end of file
nicsdevega_reading/bookshelf/urls.py
View file @
713e190e
from
django.urls
import
path
from
.views
import
index
from
.views
import
homepage
,
index_view
,
BooksView
,
AuthorsView
,
BooksDetailView
,
AuthorsDetailView
urlpatterns
=
[
path
(
''
,
index
,
name
=
'index'
)
path
(
''
,
index_view
,
name
=
'index'
),
path
(
'home/'
,
homepage
,
name
=
'home'
),
path
(
'books/'
,
BooksView
.
as_view
(),
name
=
'books'
),
path
(
'authors/'
,
AuthorsView
.
as_view
(),
name
=
'authors'
),
path
(
'books/<int:pk>/details/'
,
BooksDetailView
.
as_view
(),
name
=
'book-details'
),
path
(
'authors/<int:pk>/details/'
,
AuthorsDetailView
.
as_view
(),
name
=
'author-details'
)
]
app_name
=
'bookshelf'
app_name
=
'bookshelf'
\ No newline at end of file
nicsdevega_reading/bookshelf/views.py
View file @
713e190e
from
django.shortcuts
import
render
from
django.http
import
HttpResponse
from
.models
import
Author
,
Book
from
django.views.generic.list
import
ListView
from
django.views.generic.detail
import
DetailView
def
index
(
request
):
return
HttpResponse
(
"Hello World! This is my bookshelf!"
)
\ No newline at end of file
def
index_view
(
request
):
return
HttpResponse
(
"<h3>Hello Welcome to My Bookshelf! Please go to another page lmao.</h3>"
)
def
homepage
(
request
):
return
render
(
request
,
'bookshelf/home.html'
,
{
'name'
:
'homepage'
})
class
BooksView
(
ListView
):
model
=
Book
template_name
=
"bookshelf/books.html"
class
BooksDetailView
(
DetailView
):
model
=
Book
template_name
=
"bookshelf/book_details.html"
class
AuthorsView
(
ListView
):
model
=
Author
template_name
=
"bookshelf/authors.html"
class
AuthorsDetailView
(
DetailView
):
model
=
Author
template_name
=
"bookshelf/author_details.html"
\ No newline at end of file
nicsdevega_reading/nicsdevega_reading/settings.py
View file @
713e190e
...
...
@@ -59,7 +59,7 @@ ROOT_URLCONF = 'nicsdevega_reading.urls'
TEMPLATES
=
[
{
'BACKEND'
:
'django.template.backends.django.DjangoTemplates'
,
'DIRS'
:
[],
'DIRS'
:
[
os
.
path
.
join
(
BASE_DIR
,
'templates'
)
],
'APP_DIRS'
:
True
,
'OPTIONS'
:
{
'context_processors'
:
[
...
...
nicsdevega_reading/nicsdevega_reading/urls.py
View file @
713e190e
...
...
@@ -18,5 +18,5 @@ from django.urls import path, include
urlpatterns
=
[
path
(
'admin/'
,
admin
.
site
.
urls
),
path
(
'bookshelf'
,
include
(
'bookshelf.urls'
,
namespace
=
"bookshelf"
)),
path
(
'bookshelf
/
'
,
include
(
'bookshelf.urls'
,
namespace
=
"bookshelf"
)),
]
nicsdevega_reading/templates/base.html
0 → 100644
View file @
713e190e
<!DOCTYPE html>
<html
lang=
"en"
>
<head>
<meta
charset=
"UTF-8"
>
<meta
name=
"viewport"
content=
"width=device-width,initial-scale=1.0"
>
<link
rel=
"stylesheet"
href=
"style.css"
>
<title>
{% block title %}{% endblock %}
</title>
{% block styles %}{% endblock %}
</head>
<body>
<div
id=
"content"
>
{% block content %}{% endblock %}
</div>
{% block scripts %}{% endblock %}
</body>
</html>
\ No newline at end of file
nicsdevega_reading/templates/style.css
0 → 100644
View file @
713e190e
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