Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
sharmchua_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
Sharmaine Chua
sharmchua_reading
Commits
a434192c
Commit
a434192c
authored
Mar 28, 2023
by
Sharmaine Chua
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added templates and edited the views, urls
parent
fe433cfb
Pipeline
#3089
failed with stages
Changes
11
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
195 additions
and
6 deletions
+195
-6
models.py
sharmchua_reading/bookshelf/models.py
+8
-0
author_details.html
...reading/bookshelf/templates/bookshelf/author_details.html
+35
-0
authors.html
sharmchua_reading/bookshelf/templates/bookshelf/authors.html
+25
-0
book_details.html
...a_reading/bookshelf/templates/bookshelf/book_details.html
+31
-0
books.html
sharmchua_reading/bookshelf/templates/bookshelf/books.html
+31
-0
home.html
sharmchua_reading/bookshelf/templates/bookshelf/home.html
+21
-0
urls.py
sharmchua_reading/bookshelf/urls.py
+6
-2
views.py
sharmchua_reading/bookshelf/views.py
+23
-2
settings.py
sharmchua_reading/sharmchua_reading/settings.py
+2
-1
urls.py
sharmchua_reading/sharmchua_reading/urls.py
+1
-1
base.html
sharmchua_reading/templates/base.html
+12
-0
No files found.
sharmchua_reading/bookshelf/models.py
View file @
a434192c
from
django.db
import
models
from
django.db
import
models
from
django.core.exceptions
import
ValidationError
from
django.core.exceptions
import
ValidationError
from
django.urls
import
reverse
def
validate_isbn
(
input
):
def
validate_isbn
(
input
):
if
len
(
str
(
input
))
!=
13
:
if
len
(
str
(
input
))
!=
13
:
...
@@ -15,6 +16,10 @@ class Author(models.Model):
...
@@ -15,6 +16,10 @@ class Author(models.Model):
def
__str__
(
self
):
def
__str__
(
self
):
return
'{} {}'
.
format
(
self
.
first_name
,
self
.
last_name
)
return
'{} {}'
.
format
(
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
=
50
,
default
=
""
)
title
=
models
.
CharField
(
max_length
=
50
,
default
=
""
)
author
=
models
.
ForeignKey
(
Author
,
on_delete
=
models
.
CASCADE
)
author
=
models
.
ForeignKey
(
Author
,
on_delete
=
models
.
CASCADE
)
...
@@ -26,3 +31,6 @@ class Books(models.Model):
...
@@ -26,3 +31,6 @@ class Books(models.Model):
def
__str__
(
self
):
def
__str__
(
self
):
return
'{} by {} {}'
.
format
(
self
.
title
,
self
.
author
.
first_name
,
self
.
author
.
last_name
)
return
'{} by {} {}'
.
format
(
self
.
title
,
self
.
author
.
first_name
,
self
.
author
.
last_name
)
def
get_absolute_url
(
self
):
return
reverse
(
'bookshelf:book_details'
,
kwargs
=
{
'pk'
:
self
.
pk
})
\ No newline at end of file
sharmchua_reading/bookshelf/templates/bookshelf/author_details.html
0 → 100644
View file @
a434192c
{% extends 'base.html' %}
{% load static %}
{% block title %} {{ object.title }} {% endblock %}
{% block content %}
<h1>
{{ object }}
</h1>
<h3>
Age: {{ object.age }} years old
<br>
Nationality: {{ object.nationality }}
<br>
Bio:
<br>
{{ object.bio }}
<br>
<br>
Books by {{ object }} I love:
<br>
{% for books in object.books_set.all %}
<a
href=
"{{ books.get_absolute_url }}"
>
<li>
{{ books.title }}, {{ books.year_published }}
</li>
</a>
{% endfor %}
</h3>
{# the links to other html files #}
<center>
<a
href=
"../../home"
>
<button
type=
"button"
>
Home
</button>
</a>
<a
href=
"../../books"
>
<button
type=
"button"
>
Books
</button>
</a>
<a
href=
"../../authors"
>
<button
type=
"button"
>
Authors
</button>
</a>
</center>
{% endblock %}
\ No newline at end of file
sharmchua_reading/bookshelf/templates/bookshelf/authors.html
0 → 100644
View file @
a434192c
{% extends 'base.html' %}
{% load static %}
{% block content %}
<h1>
Sharm's Favorite Authors:
</h1>
{% for object in object_list %}
<a
href=
"{{ object.get_absolute_url }}"
>
<li>
{{ object }}
</li>
</a>
{% endfor %}
<br><br><br>
{# the links to other html files #}
<center>
<a
href=
"../home"
>
<button
type=
"button"
>
Home
</button>
</a>
<a
href=
"../books"
>
<button
type=
"button"
>
Books
</button>
</a>
</center>
{% endblock %}
\ No newline at end of file
sharmchua_reading/bookshelf/templates/bookshelf/book_details.html
0 → 100644
View file @
a434192c
{% extends 'base.html' %}
{% load static %}
{% block title %} {{ object.title }} {% endblock %}
{% block content %}
<h1>
{{ object.title }}
</h1>
<h3>
by
<a
href =
{{
object
.
author
.
get_absolute_url
}}
>
{{ object.author }}
</a>
<br>
Publisher: {{ object.publisher }}
<br>
Year Published: {{ object.year_published }}
<br>
ISBN: {{ object.ISBN }}
<br>
Blurb: {{ object.blurb }}
<br>
</h3>
{# the links to other html files #}
<center>
<a
href=
"../../home"
>
<button
type=
"button"
>
Home
</button>
</a>
<a
href=
"../../books"
>
<button
type=
"button"
>
Books
</button>
</a>
<a
href=
"../../authors"
>
<button
type=
"button"
>
Authors
</button>
</a>
</center>
{% endblock %}
\ No newline at end of file
sharmchua_reading/bookshelf/templates/bookshelf/books.html
0 → 100644
View file @
a434192c
{% extends 'base.html' %}
{% load static %}
{% block styles %}
<style>
background-color
:
#afcaff
"
;
</style>
{% endblock %}
{% block content %}
<h1>
Sharm's Favorite Books:
</h1>
{% for object in object_list %}
<a
href=
"{{ object.get_absolute_url }}"
>
<li>
{{ object.title }}
</li>
</a>
{% endfor %}
<br><br><br>
{# the links to other html files #}
<center>
<a
href=
"../home"
>
<button
type=
"button"
>
Home
</button>
</a>
<a
href=
"../authors"
>
<button
type=
"button"
>
Authors
</button>
</a>
</center>
{% endblock %}
\ No newline at end of file
sharmchua_reading/bookshelf/templates/bookshelf/home.html
0 → 100644
View file @
a434192c
{% extends 'base.html' %}
{% load static %}
{% block content %}
<center>
<h1>
Welcome to Sharm's Database of Favorite Books and Authors!
</h1>
<h3>
I like to read romance books to romanticize my life. (this is why im marupok)
<br>
Also the books here are not the books I have read because I forgot their titles...
<br>
im sorry...
<br></h3>
<br><br><br><br><br>
{# the links to other html files #}
<a
href=
"../books"
>
<button
type=
"button"
>
Books
</button>
</a>
<a
href=
"../authors"
>
<button
type=
"button"
>
Authors
</button>
</a>
</center>
{% endblock %}
\ No newline at end of file
sharmchua_reading/bookshelf/urls.py
View file @
a434192c
from
django.urls
import
path
from
django.urls
import
path
from
.views
import
index
from
.views
import
*
urlpatterns
=
[
urlpatterns
=
[
path
(
''
,
index
,
name
=
'index'
)
path
(
'home/'
,
index
,
name
=
'home'
),
path
(
'books/'
,
BooksListView
.
as_view
(),
name
=
'books_list'
),
path
(
'books/<int:pk>/details'
,
BooksDetailView
.
as_view
(),
name
=
'book_details'
),
path
(
'authors/'
,
AuthorListView
.
as_view
(),
name
=
'author_list'
),
path
(
'authors/<int:pk>/details'
,
AuthorDetailView
.
as_view
(),
name
=
'author_details'
),
]
]
app_name
=
'bookshelf'
app_name
=
'bookshelf'
\ No newline at end of file
sharmchua_reading/bookshelf/views.py
View file @
a434192c
from
django.shortcuts
import
render
from
django.shortcuts
import
render
from
django.http
import
HttpResponse
,
request
from
django.views
import
View
from
.models
import
Author
,
Books
from
django.views.generic.list
import
ListView
from
django.views.generic.detail
import
DetailView
from
django.http
import
HttpResponse
def
index
(
request
):
def
index
(
request
):
return
HttpResponse
(
'This is the bookshelf!'
)
return
render
(
request
,
'bookshelf/home.html'
,)
class
BooksListView
(
ListView
):
model
=
Books
template_name
=
'bookshelf/books.html'
class
BooksDetailView
(
DetailView
):
model
=
Books
template_name
=
'bookshelf/book_details.html'
class
AuthorListView
(
ListView
):
model
=
Author
template_name
=
'bookshelf/authors.html'
class
AuthorDetailView
(
DetailView
):
model
=
Author
template_name
=
'bookshelf/author_details.html'
\ No newline at end of file
sharmchua_reading/sharmchua_reading/settings.py
View file @
a434192c
...
@@ -59,7 +59,7 @@ ROOT_URLCONF = 'sharmchua_reading.urls'
...
@@ -59,7 +59,7 @@ ROOT_URLCONF = 'sharmchua_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'
:
[
...
@@ -123,6 +123,7 @@ USE_TZ = True
...
@@ -123,6 +123,7 @@ USE_TZ = True
# https://docs.djangoproject.com/en/3.2/howto/static-files/
# https://docs.djangoproject.com/en/3.2/howto/static-files/
STATIC_URL
=
'/static/'
STATIC_URL
=
'/static/'
STATICFILES_DIRS
=
[
os
.
path
.
join
(
BASE_DIR
,
'static'
)]
# Default primary key field type
# Default primary key field type
# https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field
# https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field
...
...
sharmchua_reading/sharmchua_reading/urls.py
View file @
a434192c
...
@@ -17,6 +17,6 @@ from django.contrib import admin
...
@@ -17,6 +17,6 @@ from django.contrib import admin
from
django.urls
import
path
,
include
from
django.urls
import
path
,
include
urlpatterns
=
[
urlpatterns
=
[
path
(
'bookshelf/'
,
include
(
'bookshelf.urls'
,
namespace
=
"bookshelf"
)),
path
(
'bookshelf/'
,
include
(
'bookshelf.urls'
)),
path
(
'admin/'
,
admin
.
site
.
urls
),
path
(
'admin/'
,
admin
.
site
.
urls
),
]
]
sharmchua_reading/templates/base.html
0 → 100644
View file @
a434192c
<!DOCTYPE html>
<html
lang=
"en"
>
<head>
<link
rel=
"stylesheet"
href=
"style.css"
>
<title>
{% block title %}My Favorite Books and Authors{% endblock %}
</title>
</head>
<body>
<div
id=
"content"
>
{% block content %}{% endblock %}
</div>
</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