Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
J
jakhermosisima_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
Joaquin Hermosisima
jakhermosisima_reading
Commits
c8d11529
Commit
c8d11529
authored
Apr 25, 2023
by
Joaquin Hermosisima
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
created forms and new templates
parent
0c64469b
Changes
10
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
192 additions
and
19 deletions
+192
-19
forms.py
jakhermosisima_reading/bookshelf/forms.py
+56
-0
add-author.html
...ima_reading/bookshelf/templates/bookshelf/add-author.html
+10
-0
add-book.html
...isima_reading/bookshelf/templates/bookshelf/add-book.html
+18
-0
author_details.html
...reading/bookshelf/templates/bookshelf/author_details.html
+6
-11
book_details.html
...a_reading/bookshelf/templates/bookshelf/book_details.html
+3
-4
edit-author.html
...ma_reading/bookshelf/templates/bookshelf/edit-author.html
+23
-0
edit-book.html
...sima_reading/bookshelf/templates/bookshelf/edit-book.html
+23
-0
urls.py
jakhermosisima_reading/bookshelf/urls.py
+8
-2
views.py
jakhermosisima_reading/bookshelf/views.py
+45
-2
db.sqlite3
jakhermosisima_reading/db.sqlite3
+0
-0
No files found.
jakhermosisima_reading/bookshelf/forms.py
0 → 100644
View file @
c8d11529
from
django
import
forms
from
.models
import
Author
,
Book
class
BookForm
(
forms
.
ModelForm
):
class
Meta
:
model
=
Book
fields
=
(
'title'
,
'author'
,
'publisher'
,
'year_published'
,
'ISBN'
,
'blurb'
,
)
labels
=
{
'title'
:
'Title'
,
'author'
:
'Author'
,
'publisher'
:
'Publisher'
,
'year_published'
:
'Year Published'
,
'ISBN'
:
'ISBN'
,
'blurb'
:
'Description'
,
}
widgets
=
{
'title'
:
forms
.
TextInput
(
attrs
=
{
'class'
:
'form-control'
}),
'author'
:
forms
.
Select
(
attrs
=
{
'class'
:
'form-control'
}),
'publisher'
:
forms
.
TextInput
(
attrs
=
{
'class'
:
'form-control'
}),
'year_published'
:
forms
.
NumberInput
(
attrs
=
{
'class'
:
'form-control'
}),
'ISBN'
:
forms
.
TextInput
(
attrs
=
{
'class'
:
'form-control'
}),
'blurb'
:
forms
.
Textarea
(
attrs
=
{
'class'
:
'form-control'
}),
}
class
AuthorForm
(
forms
.
ModelForm
):
class
Meta
:
model
=
Author
fields
=
(
'first_name'
,
'last_name'
,
'age'
,
'nationality'
,
'bio'
)
labels
=
{
'first_name'
:
'First Name'
,
'last_name'
:
'Last Name'
,
'age'
:
'Age'
,
'nationality'
:
'Nationality'
,
'bio'
:
'Bio'
,
}
widgets
=
{
'first_name'
:
forms
.
TextInput
(
attrs
=
{
'class'
:
'form-control'
}),
'last_name'
:
forms
.
TextInput
(
attrs
=
{
'class'
:
'form-control'
}),
'age'
:
forms
.
NumberInput
(
attrs
=
{
'class'
:
'form-control'
}),
'nationality'
:
forms
.
TextInput
(
attrs
=
{
'class'
:
'form-control'
}),
'bio'
:
forms
.
Textarea
(
attrs
=
{
'class'
:
'form-control'
}),
}
jakhermosisima_reading/bookshelf/templates/bookshelf/add-author.html
0 → 100644
View file @
c8d11529
{% extends "base.html" %}
{% block content %}
<h1>
Add New Author
</h1>
<form
action=
"{% url 'bookshelf:authorcreate' %}"
method=
"post"
>
{% csrf_token %}
{{ form.as_p }}
<button
type=
"submit"
>
Add Author
</button>
</form>
{% endblock %}
\ No newline at end of file
jakhermosisima_reading/bookshelf/templates/bookshelf/add-book.html
0 → 100644
View file @
c8d11529
{% extends "base.html" %}
{% block title %}Add New Book{% endblock %}
{% block content %}
<h1>
Add New Book
</h1>
<form
method=
"post"
>
{% csrf_token %}
{{ form.as_p }}
<button
type=
"submit"
>
Add Book
</button>
</form>
{% if form.errors %}
<div
class=
"alert alert-danger"
role=
"alert"
>
<strong>
Oops! Something went wrong.
</strong>
Please check the form and try again.
</div>
{% endif %}
{% endblock %}
jakhermosisima_reading/bookshelf/templates/bookshelf/author_details.html
View file @
c8d11529
{% extends "base.html" %}
{% extends "base.html" %}
{%block title%}{{object.first_name}} {{object.last_name}}{%endblock%}
{%block title%}{{object.first_name}} {{object.last_name}}{%endblock%}
{% block content %}
{% block content %}
<h1>
{{object.first_name}} {{object.last_name}}
</h1>
<h2>
{{object.first_name}} {{object.last_name}}
</h2>
<ul>
<ul>
<li>
{{object.age}}
</li>
<li>
{{object.age}}
</li>
<li>
{{object.nationality}}
</li>
<li>
{{object.nationality}}
</li>
<li>
{{object.bio}}
</li>
<li>
{{object.bio}}
</li>
</ul>
</ul>
<
h3>
Books by {{object.first_name}} {{object.last_name}} I love:
</h3
>
<
a
href=
"{% url 'bookshelf:authoredit' object.pk %}"
class=
"btn btn-primary"
><button>
Edit Author
</button></a
>
<br>
<h2>
Books by {{object.first_name}} {{object.last_name}} I love:
</h2>
<br>
<ul>
<ul>
{% for item in book_list %}
{% for item in book_list %}
<li><a
href=
"../../book/{{item.pk}}/details"
"
>
{{item.title}}
</a></li>
<li><a
href=
"../../book/{{item.pk}}/details"
"
>
{{item.title}}
</a></li>
{% endfor %}
{% endfor %}
</ul>
</ul>
<br><br><br>
<br><br><br>
{% for url in url_list %}
{% for url in url_list %}
<a
href=
"../../{{url}}"
>
{{url}}
</a>
<a
href=
"../../{{url}}"
>
{{url}}
</a>
{% endfor %}
{% endfor %}
{% endblock %}
{% endblock %}
jakhermosisima_reading/bookshelf/templates/bookshelf/book_details.html
View file @
c8d11529
{% extends "base.html" %}
{% extends "base.html" %}
{% block title %}{{object.title}}{% endblock %}
{% block title %}{{object.title}}{% endblock %}
{% block content %}
{% block content %}
<h1>
{{object.title}}
</h1>
<h2>
{{object.title}}
</h2>
<ul>
<ul>
<a
href=
"{{object.author.get_absolute_url}}"
><li>
{{object.author}}
</li></a>
<a
href=
"{{object.author.get_absolute_url}}"
><li>
{{object.author}}
</li></a>
<li>
{{object.publisher}}
</li>
<li>
{{object.publisher}}
</li>
...
@@ -13,6 +11,7 @@
...
@@ -13,6 +11,7 @@
<li>
{{object.blurb}}
</li>
<li>
{{object.blurb}}
</li>
</ul>
</ul>
<a
href=
"{% url 'bookshelf:bookedit' object.pk %}"
class=
"btn btn-primary"
><button>
Edit Book
</button></a>
<br><br><br>
<br><br><br>
{% for url in url_list %}
{% for url in url_list %}
...
...
jakhermosisima_reading/bookshelf/templates/bookshelf/edit-author.html
0 → 100644
View file @
c8d11529
{% extends "base.html" %}
{% 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
action=
"{% url 'bookshelf:authoredit' pk=form.instance.pk %}"
method=
"post"
>
{% csrf_token %}
{{ form }}
<input
type=
"submit"
value=
"Save Changes"
>
</form>
{% endblock %}
jakhermosisima_reading/bookshelf/templates/bookshelf/edit-book.html
0 → 100644
View file @
c8d11529
{% extends "base.html" %}
{% 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
action=
"{% url 'bookshelf:bookcreate' %}"
method=
"post"
>
{% csrf_token %}
{{ form }}
<input
type=
"submit"
value=
"Save Changes"
>
</form>
{% endblock %}
jakhermosisima_reading/bookshelf/urls.py
View file @
c8d11529
from
django.urls
import
path
from
django.urls
import
path
from
.views
import
BookListView
,
BookDetailView
,
AuthorListView
,
AuthorDetailView
from
.views
import
(
BookListView
,
BookDetailView
,
AuthorListView
,
AuthorDetailView
,
BookCreateView
,
BookUpdateView
,
AuthorUpdateView
,
AuthorCreateView
)
urlpatterns
=
[
urlpatterns
=
[
path
(
'books/'
,
BookListView
.
as_view
(),
name
=
'book-list'
),
path
(
'books/'
,
BookListView
.
as_view
(),
name
=
'book-list'
),
path
(
'book/<int:pk>/details'
,
BookDetailView
.
as_view
(),
name
=
'bookitem'
),
path
(
'book/<int:pk>/details'
,
BookDetailView
.
as_view
(),
name
=
'bookitem'
),
path
(
'authors/'
,
AuthorListView
.
as_view
(),
name
=
'author-list'
),
path
(
'authors/'
,
AuthorListView
.
as_view
(),
name
=
'author-list'
),
path
(
'authors/<int:pk>/details'
,
AuthorDetailView
.
as_view
(),
name
=
"authoritem"
)
path
(
'authors/<int:pk>/details'
,
AuthorDetailView
.
as_view
(),
name
=
"authoritem"
),
path
(
'books/add/'
,
BookCreateView
.
as_view
(),
name
=
"bookcreate"
),
path
(
'authors/add/'
,
AuthorCreateView
.
as_view
(),
name
=
"authorcreate"
),
path
(
'books/<int:pk>/edit/'
,
BookUpdateView
.
as_view
(),
name
=
'bookedit'
),
path
(
'authors/<int:pk>/edit/'
,
AuthorUpdateView
.
as_view
(),
name
=
'authoredit'
),
]
]
app_name
=
'bookshelf'
app_name
=
'bookshelf'
\ No newline at end of file
jakhermosisima_reading/bookshelf/views.py
View file @
c8d11529
from
django.shortcuts
import
render
from
django.shortcuts
import
render
,
redirect
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
Author
,
Book
from
.models
import
Author
,
Book
from
.forms
import
BookForm
,
AuthorForm
from
django.views.generic.edit
import
CreateView
,
UpdateView
from
django.urls
import
reverse
,
reverse_lazy
class
BookListView
(
ListView
):
class
BookListView
(
ListView
):
model
=
Book
model
=
Book
...
@@ -40,3 +43,43 @@ class AuthorDetailView(DetailView):
...
@@ -40,3 +43,43 @@ class AuthorDetailView(DetailView):
context
[
'book_list'
]
=
Book
.
objects
.
filter
(
author
=
self
.
object
.
pk
)
context
[
'book_list'
]
=
Book
.
objects
.
filter
(
author
=
self
.
object
.
pk
)
return
context
return
context
def
add_book_view
(
request
):
form
=
BookForm
()
if
request
.
method
==
'POST'
:
form
=
BookForm
(
request
.
POST
)
if
form
.
is_valid
():
form
.
save
()
return
redirect
(
'bookshelf:bookitem'
,
pk
=
form
.
instance
.
pk
)
return
render
(
request
,
'bookshelf/add-book.html'
,
{
'form'
:
form
})
class
BookCreateView
(
CreateView
):
model
=
Book
form_class
=
BookForm
template_name
=
"bookshelf/add-book.html"
def
get_success_url
(
self
):
return
reverse
(
'bookshelf:bookitem'
,
args
=
(
self
.
object
.
pk
,))
class
BookUpdateView
(
UpdateView
):
model
=
Book
form_class
=
BookForm
template_name
=
"bookshelf/edit-book.html"
def
get_success_url
(
self
):
return
reverse_lazy
(
'bookshelf:bookitem'
,
args
=
[
self
.
object
.
pk
])
class
AuthorUpdateView
(
UpdateView
):
model
=
Author
form_class
=
AuthorForm
template_name
=
"bookshelf/edit-author.html"
def
get_success_url
(
self
):
return
reverse_lazy
(
'bookshelf:authoritem'
,
args
=
[
self
.
object
.
pk
])
class
AuthorCreateView
(
CreateView
):
model
=
Author
form_class
=
AuthorForm
template_name
=
"bookshelf/add-author.html"
def
get_success_url
(
self
):
return
reverse
(
'bookshelf:authoritem'
,
args
=
(
self
.
object
.
pk
,))
\ No newline at end of file
jakhermosisima_reading/db.sqlite3
View file @
c8d11529
No preview for this file type
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