Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
albomediano_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
Al Vincent E. Bomediano
albomediano_reading
Commits
0f8bdd92
Commit
0f8bdd92
authored
Apr 27, 2023
by
Al Vincent E. Bomediano
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Finished updating new pages
parent
065ce47b
Changes
11
Show whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
200 additions
and
129 deletions
+200
-129
forms.py
albomediano_reading/bookshelf/forms.py
+9
-11
models.py
albomediano_reading/bookshelf/models.py
+14
-14
add-author.html
...ano_reading/bookshelf/templates/bookshelf/add-author.html
+23
-0
add-book.html
...diano_reading/bookshelf/templates/bookshelf/add-book.html
+12
-7
author_details.html
...reading/bookshelf/templates/bookshelf/author_details.html
+25
-16
book_details.html
...o_reading/bookshelf/templates/bookshelf/book_details.html
+23
-12
edit-author.html
...no_reading/bookshelf/templates/bookshelf/edit-author.html
+23
-0
edit-book.html
...iano_reading/bookshelf/templates/bookshelf/edit-book.html
+23
-0
home.html
albomediano_reading/bookshelf/templates/bookshelf/home.html
+2
-2
urls.py
albomediano_reading/bookshelf/urls.py
+13
-13
views.py
albomediano_reading/bookshelf/views.py
+33
-54
No files found.
albomediano_reading/bookshelf/forms.py
View file @
0f8bdd92
from
django
import
forms
from
django
import
forms
from
.models
import
Author
,
Books
class
IndexCardForm
(
forms
.
Form
):
class
BookForm
(
forms
.
Model
Form
):
name
=
forms
.
CharField
(
label
=
'Full Name'
,
max_length
=
100
)
class
Meta
:
section
=
forms
.
CharField
(
label
=
'CSCI40 Section'
,
max_length
=
5
)
model
=
Books
age
=
forms
.
IntegerField
(
label
=
'Current Age'
)
fields
=
'__all__'
class
AddBookForm
(
forms
.
Form
):
class
AuthorForm
(
forms
.
ModelForm
):
title
=
forms
.
CharField
(
label
=
'Title'
,
max_length
=
100
)
class
Meta
:
# author = forms.ForeignKey(Author, on_delete=forms.CASCADE)
model
=
Author
publisher
=
forms
.
CharField
(
label
=
'Publisher'
,
max_length
=
100
)
fields
=
'__all__'
year_published
=
forms
.
IntegerField
(
label
=
'Year Published'
)
ISBN
=
forms
.
IntegerField
(
label
=
'ISBN'
)
blurb
=
forms
.
CharField
(
label
=
'Blurb'
,
max_length
=
200
)
albomediano_reading/bookshelf/models.py
View file @
0f8bdd92
...
@@ -3,29 +3,29 @@ from django.urls import reverse
...
@@ -3,29 +3,29 @@ from django.urls import reverse
class
Author
(
models
.
Model
):
class
Author
(
models
.
Model
):
first_name
=
models
.
CharField
(
max_length
=
100
)
first_name
=
models
.
CharField
(
max_length
=
50
,
default
=
""
)
last_name
=
models
.
CharField
(
max_length
=
100
)
last_name
=
models
.
CharField
(
max_length
=
30
,
default
=
""
)
age
=
models
.
IntegerField
()
age
=
models
.
IntegerField
(
default
=
0
)
nationality
=
models
.
CharField
(
max_length
=
100
)
nationality
=
models
.
CharField
(
max_length
=
30
,
default
=
""
)
bio
=
models
.
CharField
(
max_length
=
700
)
bio
=
models
.
TextField
(
max_length
=
700
,
default
=
""
)
def
__str__
(
self
):
def
__str__
(
self
):
return
'{}, {}'
.
format
(
self
.
last_name
,
self
.
first_name
)
return
self
.
last_name
def
get_absolute_url
(
self
):
def
get_absolute_url
(
self
):
return
reverse
(
'
bookshelf:
author-details'
,
kwargs
=
{
'pk'
:
self
.
pk
})
return
reverse
(
'author-details'
,
kwargs
=
{
'pk'
:
self
.
pk
})
class
Books
(
models
.
Model
):
class
Books
(
models
.
Model
):
title
=
models
.
CharField
(
max_length
=
100
)
title
=
models
.
CharField
(
max_length
=
50
,
default
=
""
)
author
=
models
.
ForeignKey
(
Author
,
on_delete
=
models
.
CASCADE
)
author
=
models
.
ForeignKey
(
Author
,
on_delete
=
models
.
CASCADE
)
publisher
=
models
.
CharField
(
max_length
=
100
)
publisher
=
models
.
CharField
(
max_length
=
50
,
default
=
""
)
year_published
=
models
.
IntegerField
(
max_length
=
4
)
year_published
=
models
.
IntegerField
(
default
=
0
)
ISBN
=
models
.
IntegerField
(
max_length
=
13
)
ISBN
=
models
.
IntegerField
(
default
=
0
)
blurb
=
models
.
CharField
(
max_length
=
200
)
blurb
=
models
.
TextField
(
max_length
=
200
,
default
=
""
)
def
__str__
(
self
):
def
__str__
(
self
):
return
'{} by {}'
.
format
(
self
.
title
,
self
.
author
)
return
self
.
title
def
get_absolute_url
(
self
):
def
get_absolute_url
(
self
):
return
reverse
(
'book
shelf:book
-details'
,
kwargs
=
{
'pk'
:
self
.
pk
})
return
reverse
(
'book-details'
,
kwargs
=
{
'pk'
:
self
.
pk
})
albomediano_reading/bookshelf/templates/bookshelf/add-author.html
0 → 100644
View file @
0f8bdd92
{% extends 'base.html' %}
{% load static %}
{% block title %} Add New Author {% endblock %}
{% block content %}
{{ form.non_field_errors }}
{% for field in form %}
{% if field.errors %}
<p>
{{ field.label }} has the following errors:
</p>
<ul>
{% for error in field.errors %}
<li>
{{ error }}
</li>
{% endfor %}
</ul>
{% endif %}
{% endfor %}
<form
method =
"post"
>
{% csrf_token %}
{% for field in form %}
{{field.label}}: {{field}}
<br><br>
{% endfor %}
<input
type=
"submit"
value=
"Add Author"
>
</form>
{% endblock %}
albomediano_reading/bookshelf/templates/bookshelf/add-book.html
View file @
0f8bdd92
{% extends 'base.html' %}
{% load static %}
{% block title %} Add New Book {% endblock %}
{% block content %}
{% block content %}
{{ form.non_field_errors }}
{{ form.non_field_errors }}
{% for field in form %}
{% for field in form %}
{% if field.errors %}
{% if field.errors %}
<p>
{{ field.label }} has the following errors:
</p>
<p>
{{ field.label }} has the following errors:
</p>
<ul>
<ul>
{% for error in field.errors %}
{% for error in field.errors %}
<li>
{{ error }}
</li>
<li>
{{ error }}
</li>
...
@@ -10,9 +13,11 @@
...
@@ -10,9 +13,11 @@
</ul>
</ul>
{% endif %}
{% endif %}
{% endfor %}
{% endfor %}
<form
action=
"/books/add/"
method=
"post"
>
<form
method =
"post"
>
{% csrf_token %}
{% csrf_token %}
{{ form }}
{% for field in form %}
<input
type=
"submit"
value=
"Submit"
>
{{field.label}}: {{field}}
<br><br>
</form>
{% endfor %}
<input
type=
"submit"
value=
"Add Book"
>
</form>
{% endblock %}
{% endblock %}
albomediano_reading/bookshelf/templates/bookshelf/author_details.html
View file @
0f8bdd92
{% extends 'base.html' %}
{% extends 'base.html' %}
{% load static%}
{% load static %}
{% block title %} {{ object.first_name }} {{ object.last_name }} {% endblock %}
{% block title %}My Favorite Books{% endblock %}
{% block content %}
{% block content %}
<h1>
{{ object.author }}
</h1>
<h1>
{{ object.first_name }} {{ object.last_name }}
</h1>
{{ object.first_name }} {{ object.last_name }}
<br>
{{ object.nationality }}
<br>
<body>
{{ object.bio }}
<br>
{{ object.age }}
<br>
<br>
{{ object.nationality }}
<br>
Books by {{ object.first_name }} {{ objects.last_name }} I like:
{{ object.bio }}
<br>
<br>
<a
href=
"/bookshelf/authors/{{object.id}}/edit"
><button>
Edit Author
</button></a><br><br>
{% for object in author.books_set.all %}
<a
href=
"{{ object.get_absolute_url }}"
>
{{ object }}
<br></a>
Books by {{ object.first_name }} {{ object.last_name }} I love:
<br>
{% endfor %}
{% for object in author.books_set.all %}
<br>
<li>
<a
href=
"/home"
>
Home
</a>
<a
href=
"/books"
>
Books
</a>
<a
href=
"/authors"
>
Authors
</a>
<a
href=
"{{ object.get_absolute_url }}"
>
{{ object.title }}
</a>
</li>
{% endfor %}
</body>
<footer>
<br><br>
<a
href=
"/bookshelf/home"
>
Home
</a>
<a
href=
"/bookshelf/books"
>
Books
</a>
<a
href=
"/bookshelf/authors"
>
Authors
</footer>
{% endblock %}
{% endblock %}
albomediano_reading/bookshelf/templates/bookshelf/book_details.html
View file @
0f8bdd92
{% extends 'base.html' %}
{% extends 'base.html' %}
{% load static%}
{% load static %}
{% block title %} {{ object.title }} {% endblock %}
{% block title %}My Favorite Books{% endblock %}
{% block content %}
{% block content %}
<h1>
{{ object.title }}
</h1>
<a
href=
"/authors/{{ object.author.pk }}/details"
>
{{ object.author}}
</a>
<h1>
{{ object.title }}
</h1>
<br>
{{ object.publisher }}
<br>
<body>
{{ object.year_published }}
<br>
<a
href=
"{{ object.author.get_absolute_url }}"
>
{{ object.ISBN }}
<br>
{{ object.author.first_name }} {{ object.author.last_name }}
<br>
{{ object.blurb }}
<br>
</a>
<a
href=
"/home"
>
Home
</a>
<a
href=
"/books"
>
Books
</a>
<a
href=
"/authors"
>
Authors
</a>
{{ object.publisher }}
<br>
{{ object.year_published }}
<br>
{{ object.ISBN }}
<br>
{{ object.blurb }}
<br><br>
<a
href=
"/bookshelf/books/{{object.id}}/edit"
><button>
Edit Book
</button></a>
</body>
<footer>
<br><br>
<a
href=
"/bookshelf/home"
>
Home
</a>
<a
href=
"/bookshelf/books"
>
Books
</a>
<a
href=
"/bookshelf/authors"
>
Authors
</footer>
{% endblock %}
{% endblock %}
albomediano_reading/bookshelf/templates/bookshelf/edit-author.html
0 → 100644
View file @
0f8bdd92
{% extends 'base.html' %}
{% load static %}
{% block title %} Edit Author {% endblock %}
{% block content %}
{{ form.non_field_errors }}
{% for field in form %}
{% if field.errors %}
<p>
{{ field.label }} has the following errors:
</p>
<ul>
{% for error in field.errors %}
<li>
{{ error }}
</li>
{% endfor %}
</ul>
{% endif %}
{% endfor %}
<form
method =
"post"
>
{% csrf_token %}
{% for field in form %}
{{field.label}}: {{field}}
<br><br>
{% endfor %}
<input
type=
"submit"
value=
"Save Changes"
>
</form>
{% endblock %}
albomediano_reading/bookshelf/templates/bookshelf/edit-book.html
0 → 100644
View file @
0f8bdd92
{% extends 'base.html' %}
{% load static %}
{% block title %} Edit Book {% endblock %}
{% block content %}
{{ form.non_field_errors }}
{% for field in form %}
{% if field.errors %}
<p>
{{ field.label }} has the following errors:
</p>
<ul>
{% for error in field.errors %}
<li>
{{ error }}
</li>
{% endfor %}
</ul>
{% endif %}
{% endfor %}
<form
method =
"post"
>
{% csrf_token %}
{% for field in form %}
{{field.label}}: {{field}}
<br><br>
{% endfor %}
<input
type=
"submit"
value=
"Save Changes"
>
</form>
{% endblock %}
albomediano_reading/bookshelf/templates/bookshelf/home.html
View file @
0f8bdd92
...
@@ -6,7 +6,7 @@
...
@@ -6,7 +6,7 @@
<h1>
Welcome to Al's Database of
<h1>
Welcome to Al's Database of
Favorite Books and Authors
</h1>
Favorite Books and Authors
</h1>
<h3>
I barely read books, and when I do, they are mostly Japanese Light Novels or Manga. But recently I have been into Webtoons!
</h3>
<h3>
I barely read books, and when I do, they are mostly Japanese Light Novels or Manga. But recently I have been into Webtoons!
</h3>
<a
href=
"/books
"
>
Books
</a>
<a
href=
"/authors"
>
Authors
</a
>
<a
href=
"/books
helf/books"
>
Books
</a>
<a
href=
"/bookshelf/authors"
>
Authors
</a><br
>
<br>
<br>
<a
href=
"/books
/add"
>
Add Book
</a>
<a
href=
"
/authors/add"
>
Add Author
</a>
<a
href=
"/books
helf/books/add"
>
Add Book
</a>
<a
href =
"/bookshelf
/authors/add"
>
Add Author
</a>
{% endblock %}
{% endblock %}
\ No newline at end of file
albomediano_reading/bookshelf/urls.py
View file @
0f8bdd92
from
django.urls
import
path
from
django.urls
import
path
from
.
import
views
from
.views
import
(
from
.views
import
(
BooksView
,
BooksDetails
View
,
HomepageView
,
BooksListView
,
BooksDetail
View
,
Authors
View
,
AuthorsDetails
View
,
Authors
ListView
,
AuthorsDetailView
,
BookCreate
View
,
index_card_view
,
add_book_v
iew
BookUpdateView
,
AuthorCreateView
,
AuthorUpdateV
iew
)
)
urlpatterns
=
[
urlpatterns
=
[
path
(
'home/'
,
views
.
home_view
,
name
=
'home'
),
path
(
'home/'
,
HomepageView
,
name
=
'home'
),
path
(
'books/'
,
BooksView
.
as_view
(),
name
=
'books-list'
),
path
(
'books/'
,
BooksListView
.
as_view
(),
name
=
'books-list'
),
path
(
'books/<int:pk>/details'
,
BooksDetailsView
.
as_view
(),
name
=
'book-details'
),
path
(
'books/<int:pk>/details/'
,
BooksDetailView
.
as_view
(),
name
=
'book-details'
),
path
(
'authors/'
,
AuthorsView
.
as_view
(),
name
=
'authors-list'
),
path
(
'authors/'
,
AuthorsListView
.
as_view
(),
name
=
'authors-list'
),
path
(
'authors/<int:pk>/details'
,
AuthorsDetailsView
.
as_view
(),
name
=
'author-details'
),
path
(
'authors/<int:pk>/details/'
,
AuthorsDetailView
.
as_view
(),
name
=
'author-details'
),
path
(
'books/add/'
,
BookCreateView
.
as_view
(),
name
=
'add-book'
),
path
(
'index_card'
,
index_card_view
,
name
=
'index_card'
),
path
(
'authors/add/'
,
AuthorCreateView
.
as_view
(),
name
=
'add-author'
),
path
(
'books/add/'
,
add_book_view
,
name
=
'add-book'
),
path
(
'books/<pk>/edit/'
,
BookUpdateView
.
as_view
(),
name
=
'edit-book'
),
path
(
'authors/<pk>/edit/'
,
AuthorUpdateView
.
as_view
(),
name
=
'edit-author'
),
]
]
app_name
=
"bookshelf"
app_name
=
"bookshelf"
albomediano_reading/bookshelf/views.py
View file @
0f8bdd92
from
django.forms
import
NameForm
,
HttpResponse
from
django.shortcuts
import
render
from
django.shortcuts
import
render
from
django.views.generic.list
import
ListView
from
django.views.generic.list
import
ListView
from
django.views.generic.detail
import
DetailView
from
django.views.generic.detail
import
DetailView
from
.models
import
Books
,
Author
from
django.views.generic.edit
import
CreateView
,
UpdateView
from
.forms
import
IndexCardForm
,
AddBookForm
from
.models
import
Author
,
Books
def
home_view
(
request
):
def
HomepageView
(
request
):
return
render
(
request
,
'bookshelf/home.html'
)
return
render
(
request
,
'bookshelf/home.html'
)
class
BooksView
(
ListView
):
class
BookCreateView
(
CreateView
):
model
=
Books
fields
=
'__all__'
template_name
=
'bookshelf/add-book.html'
class
AuthorCreateView
(
CreateView
):
model
=
Author
fields
=
'__all__'
template_name
=
'bookshelf/add-author.html'
class
BookUpdateView
(
UpdateView
):
model
=
Books
fields
=
'__all__'
template_name
=
'bookshelf/edit-book.html'
class
AuthorUpdateView
(
UpdateView
):
model
=
Author
fields
=
'__all__'
template_name
=
'bookshelf/edit-author.html'
class
BooksListView
(
ListView
):
model
=
Books
model
=
Books
template_name
=
'bookshelf/books.html'
template_name
=
'bookshelf/books.html'
class
BooksDetail
s
View
(
DetailView
):
class
BooksDetailView
(
DetailView
):
model
=
Books
model
=
Books
template_name
=
'bookshelf/book_details.html'
template_name
=
'bookshelf/book
s
_details.html'
class
AuthorsView
(
ListView
):
class
Authors
List
View
(
ListView
):
model
=
Author
model
=
Author
template_name
=
'bookshelf/authors.html'
template_name
=
'bookshelf/authors.html'
class
AuthorsDetail
s
View
(
DetailView
):
class
AuthorsDetailView
(
DetailView
):
model
=
Author
model
=
Author
template_name
=
'bookshelf/author_details.html'
template_name
=
'bookshelf/author_details.html'
def
index_card_view
(
request
):
# Checking for POST request
if
request
.
method
==
'POST'
:
# Creating a Form object
form
=
NameForm
(
request
.
POST
)
# Checking if the inputs are valid
if
form
.
is_valid
():
return
HttpResponse
(
'Hello {} from Section {}'
.
format
(
# Getting data from our form that have been validated
form
.
cleaned_data
[
'name'
],
form
.
cleanded_data
[
'section'
]
)
)
else
:
# returning the same form object in the context allows
# for rendering the errors that are in the form object
return
render
(
request
,
'index.html'
,
{
'form'
:
form
})
else
:
form
=
IndexCardForm
()
return
render
(
request
,
'index.html'
,
{
'form'
:
form
})
def
add_book_view
(
request
):
if
request
.
method
==
'POST'
:
form
=
NameForm
(
request
.
POST
)
if
form
.
is_valid
():
return
HttpResponse
(
'Author: {}, Publisher: {}, Year Published: {}, ISBN: {}, Blurb: {}'
.
format
(
form
.
cleaned_data
[
'author'
],
form
.
cleaned_data
[
'publisher'
],
form
.
cleaned_data
[
'year_published'
],
form
.
cleaned_data
[
'ISBN'
],
form
.
cleaned_data
[
'blurb'
],
)
)
else
:
return
render
(
request
,
'index.html'
,
{
'form'
:
form
})
else
:
form
=
AddBookForm
()
return
render
(
request
,
'index.html'
,
{
'form'
:
form
})
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