Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
neptunesy_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
Star Neptune R. Sy
neptunesy_reading
Commits
38f32a2e
Commit
38f32a2e
authored
Apr 25, 2023
by
Star Neptune R. Sy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add-book is working
parent
4dc16d41
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
39 additions
and
20 deletions
+39
-20
add-author.html
...esy_reading/bookshelf/templates/bookshelf/add-author.html
+12
-12
add-book.html
...unesy_reading/bookshelf/templates/bookshelf/add-book.html
+10
-6
views.py
neptunesy_reading/bookshelf/views.py
+17
-2
db.sqlite3
neptunesy_reading/db.sqlite3
+0
-0
No files found.
neptunesy_reading/bookshelf/templates/bookshelf/add-author.html
View file @
38f32a2e
...
...
@@ -2,18 +2,18 @@
{% block title %} Add new Author {% endblock %}
{% block additional %} Add new Author {% endblock %}
{% block content %}
<form
action=
"/"
method=
"post"
>
<form
id=
'addBook'
action=
"/"
method=
"post"
>
{% csrf_token %}
<label
for=
"title"
>
Title:
</label>
<input
type=
"text"
id=
"textField"
name=
"title"
><br><br>
<label
for=
"author"
>
Author:
</label>
<select
id=
"selectField"
name=
'author'
>
{% for author in object_list %}
<option
value=
{{
author
}}
>
{{ author }}
</option>
{% endfor %}
</select>
<label
for=
"firstName"
>
First name:
</label>
<input
type=
"text"
id=
"textField"
name=
"firstName"
><br><br>
<label
for=
"lastName"
>
Last name:
</label>
<input
type=
"text"
id=
"textField"
name=
"lastName"
><br><br>
<label
for=
"age"
>
Age:
</label>
<input
type=
"number"
id=
"textField"
name=
"age"
><br><br>
<label
for=
"publisher"
>
Publisher:
</label>
<input
type=
"text"
id=
"textField"
name=
"publisher"
><br><br>
<label
for=
"yearPublished"
>
Year published:
</label>
...
...
@@ -21,9 +21,9 @@
<label
for=
"ISBN"
>
ISBN:
</label>
<input
type=
"text"
id=
"textField"
name=
"ISBN"
><br><br>
<label
for=
"blurb"
>
Blurb:
</label>
<input
type=
"text"
id=
"textField"
name=
"blurb"
><br><br>
<input
type=
"submit"
id=
"submitButton"
value=
"Submit"
>
<textarea
name=
"blurb"
form=
'addBook'
rows=
50
cols=
50
></textarea>
<input
type=
"text"
id=
"textField"
name=
"blurb"
><br><br>
<input
type=
"submit"
id=
"submitButton"
value=
"Add book"
>
</form>
{% endblock %}
\ No newline at end of file
neptunesy_reading/bookshelf/templates/bookshelf/add-book.html
View file @
38f32a2e
...
...
@@ -2,16 +2,19 @@
{% block title %} Add new Book {% endblock %}
{% block additional %} Add new Book {% endblock %}
{% block content %}
<form
action=
"/
"
method=
"post"
>
<form
id=
"addBook
"
method=
"post"
>
{% csrf_token %}
<label
for=
"title"
>
Title:
</label>
{{ form.as_p }}
<!--<label for="title">Title:</label>
<input type="text" id="textField" name="title"><br><br>
<label for="author">Author:</label>
<select
id=
"selectField"
name=
'author'
>
{% for author in object
_list
%}
<option
value=
{{
author
}}
>
{{ author
}}
</option>
<select
form="addBook"
id="selectField" name='author'>
{% for author in object %}
<option value={{
author}}>{{author
}}</option>
{% endfor %}
</select>
<label for="publisher">Publisher:</label>
...
...
@@ -21,7 +24,8 @@
<label for="ISBN">ISBN:</label>
<input type="text" id="textField" name="ISBN"><br><br>
<label for="blurb">Blurb:</label>
<input
type=
"text"
id=
"textField"
name=
"blurb"
><br><br>
<textarea form="addBook" name="blurb"></textarea>
<input type="text" id="textField" name="blurb"><br><br>-->
<input
type=
"submit"
id=
"submitButton"
value=
"Submit"
>
</form>
...
...
neptunesy_reading/bookshelf/views.py
View file @
38f32a2e
from
django.shortcuts
import
render
from
django.http.response
import
HttpResponseRedirect
from
django.views.generic.detail
import
DetailView
from
django.views.generic.list
import
ListView
from
django.views.generic.edit
import
CreateView
,
UpdateView
from
.models
import
Author
,
Book
def
homeView
(
request
):
return
render
(
request
,
'home.html'
)
...
...
@@ -14,10 +16,23 @@ class BooksView(ListView):
class
BooksAddView
(
CreateView
):
model
=
Author
model
=
Book
fields
=
'__all__'
template_name
=
"bookshelf/add-book.html"
def
post
(
self
,
request
,
*
args
,
**
kwargs
):
title
=
request
.
POST
.
get
(
'title'
)
author
=
request
.
POST
.
get
(
'author'
)
publisher
=
request
.
POST
.
get
(
'publisher'
)
yearPublished
=
request
.
POST
.
get
(
'year_published'
)
ISBN
=
request
.
POST
.
get
(
'ISBN'
)
blurb
=
request
.
POST
.
get
(
'blurb'
)
s
=
Book
(
title
=
title
,
author
=
Author
.
objects
.
get
(
pk
=
author
),
publisher
=
publisher
,
year_published
=
yearPublished
,
ISBN
=
ISBN
,
blurb
=
blurb
)
newUrl
=
s
.
save
()
return
HttpResponseRedirect
(
str
(
s
.
get_absolute_url
())
+
"/details/"
)
class
BooksDetail
(
DetailView
):
model
=
Book
...
...
@@ -28,7 +43,7 @@ class AuthorView(ListView):
model
=
Author
template_name
=
"bookshelf/authors.html"
class
AuthorAddView
(
List
View
):
class
AuthorAddView
(
Create
View
):
model
=
Book
template_name
=
"bookshelf/add-author.html"
...
...
neptunesy_reading/db.sqlite3
View file @
38f32a2e
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