Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
J
justinreyes_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
Justin Reyes
justinreyes_reading
Commits
02285178
Commit
02285178
authored
Apr 24, 2023
by
justin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
misc: updated forms.py to use ModelForm API, added url routing to /books/add
parent
ffbf4449
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
44 additions
and
6 deletions
+44
-6
forms.cpython-310.pyc
...reyes_reading/bookshelf/__pycache__/forms.cpython-310.pyc
+0
-0
urls.cpython-310.pyc
...nreyes_reading/bookshelf/__pycache__/urls.cpython-310.pyc
+0
-0
views.cpython-310.pyc
...reyes_reading/bookshelf/__pycache__/views.cpython-310.pyc
+0
-0
forms.py
justinreyes_reading/bookshelf/forms.py
+17
-6
add-book.html
...reyes_reading/bookshelf/templates/bookshelf/add-book.html
+19
-0
urls.py
justinreyes_reading/bookshelf/urls.py
+2
-0
views.py
justinreyes_reading/bookshelf/views.py
+6
-0
No files found.
justinreyes_reading/bookshelf/__pycache__/forms.cpython-310.pyc
0 → 100644
View file @
02285178
File added
justinreyes_reading/bookshelf/__pycache__/urls.cpython-310.pyc
View file @
02285178
No preview for this file type
justinreyes_reading/bookshelf/__pycache__/views.cpython-310.pyc
View file @
02285178
No preview for this file type
justinreyes_reading/bookshelf/forms.py
View file @
02285178
from
django
import
forms
from
.models
import
Author
,
Books
class
BookForm
(
forms
.
Form
):
title
=
forms
.
CharField
(
label
=
"Title"
,
max_length
=
255
)
publisher
=
forms
.
CharField
(
label
=
"Publisher"
,
max_length
=
255
)
year_published
=
forms
.
IntegerField
(
label
=
"Year Published"
)
isbn
=
forms
.
IntegerField
(
label
=
"ISBN"
)
blurb
=
forms
.
CharField
(
label
=
"Blurb"
,
widget
=
forms
.
Textarea
)
class
BookForm
(
forms
.
ModelForm
):
# title = forms.CharField(label="Title", max_length=255)
# publisher = forms.CharField(label="Publisher", max_length=255)
# year_published = forms.IntegerField(label="Year Published")
# isbn = forms.IntegerField(label="ISBN")
# blurb = forms.CharField(label="Blurb", widget=forms.Textarea)
class
Meta
:
model
=
Books
fields
=
[
"title"
,
"author"
,
"publisher"
,
"year_published"
,
"isbn"
,
"blurb"
,
]
justinreyes_reading/bookshelf/templates/bookshelf/add-book.html
0 → 100644
View file @
02285178
{% extends 'base.html' %}
{% block content %}
{{ form.non_field_errors }}
{% for field in form %}
{% if field.errors %}
<p>
{{field.label}} has errors:
</p>
<ul>
{% for error in field.errors %}
<li>
{{ error }}
</li>
{% endfor %}
</ul>
{% endif %}
{% endfor %}
<form
action=
"/books/add"
method=
"post"
>
{% csrf_token %}
{{form}}
<input
type=
"submit"
value=
"Submit"
/>
</form>
{% endblock %}
justinreyes_reading/bookshelf/urls.py
View file @
02285178
from
django.urls
import
path
from
.views
import
(
index
,
add_book
,
BookListView
,
BookDetailView
,
AuthorListView
,
...
...
@@ -11,6 +12,7 @@ urlpatterns = [
path
(
"home/"
,
index
,
name
=
"home"
),
path
(
"books/"
,
BookListView
.
as_view
(),
name
=
"book-list"
),
path
(
"books/<int:pk>/details"
,
BookDetailView
.
as_view
(),
name
=
"book-detail"
),
path
(
"books/add"
,
add_book
,
name
=
"add-book"
),
path
(
"authors/"
,
AuthorListView
.
as_view
(),
name
=
"author-list"
),
path
(
"author/<int:pk>/details"
,
AuthorDetailView
.
as_view
(),
name
=
"author-detail"
),
]
justinreyes_reading/bookshelf/views.py
View file @
02285178
...
...
@@ -3,6 +3,7 @@ from django.views import View
from
django.views.generic.list
import
ListView
from
django.views.generic.detail
import
DetailView
from
.models
import
Author
,
Books
from
.forms
import
BookForm
def
index
(
request
):
...
...
@@ -12,6 +13,11 @@ def index(request):
)
def
add_book
(
request
):
form
=
BookForm
()
return
render
(
request
,
"bookshelf/add-book.html"
,
{
"form"
:
form
})
class
BookListView
(
ListView
):
model
=
Books
template_name
=
"bookshelf/books.html"
...
...
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