Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
D
Deokhyun_Lee_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
Deokhyun Lee
Deokhyun_Lee_reading
Commits
8f7b159e
Commit
8f7b159e
authored
Apr 25, 2023
by
Deokhyun Lee
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
now updating existing fields on Books works correctly
parent
8ae0776b
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
35 additions
and
5 deletions
+35
-5
book_details.html
...n_Lee_reading/bookshelf/templates/books/book_details.html
+1
-1
edit-book.html
...hyun_Lee_reading/bookshelf/templates/books/edit-book.html
+11
-0
urls.py
Deokhyun_Lee_reading/bookshelf/urls.py
+5
-3
views.py
Deokhyun_Lee_reading/bookshelf/views.py
+18
-1
No files found.
Deokhyun_Lee_reading/bookshelf/templates/books/book_details.html
View file @
8f7b159e
...
...
@@ -23,7 +23,7 @@
<p>
No Available Books.
</p>
{% endif %}
<ul>
<li
><button
type=
"button"
onclick=
"
alert('You pressed the button!')"
>
Click me!
</button></li>
<li
><button
type=
"button"
onclick=
"
window.location.href='/books/{{book.pk}}/edit'"
>
Edit Books
</button></li>
<li><a
href=
"/home"
>
Home
</a>
&
nbsp
&
nbsp
&
nbsp
&
nbsp
&
nbsp
<a
href=
"/books"
>
Books
</a>
&
nbsp
&
nbsp
&
nbsp
&
nbsp
&
nbsp
<a
href=
"/authors"
>
Authors
</a></li>
</ul>
{% endblock %}
\ No newline at end of file
Deokhyun_Lee_reading/bookshelf/templates/books/edit-book.html
0 → 100644
View file @
8f7b159e
{% extends 'base.html'%}
{% block title %}
Add New Book
{% endblock %}
{% block content %}
<form
method=
"post"
>
{% csrf_token %}
{{ form.as_p }}
<button
type=
"submit"
>
Save Changes
</button>
</form>
{% endblock %}
\ No newline at end of file
Deokhyun_Lee_reading/bookshelf/urls.py
View file @
8f7b159e
from
django.urls
import
path
from
.views
import
HomeView
,
AuthorListView
,
AuthorDetailView
,
AuthorAddListView
,
BookListView
,
BookDetailView
,
BookAddListView
from
.views
import
HomeView
,
AuthorListView
,
AuthorDetailView
,
AuthorAddListView
,
BookListView
,
BookDetailView
,
BookAddListView
,
BookEditView
urlpatterns
=
[
# for Home (landing page)
...
...
@@ -7,9 +7,11 @@ urlpatterns = [
# for Authors page
path
(
'authors/'
,
AuthorListView
.
as_view
(),
name
=
'authors'
),
path
(
'authors/<int:pk>/details'
,
AuthorDetailView
.
as_view
(),
name
=
'author_detail'
),
path
(
'authors/add'
,
AuthorAddListView
.
as_view
(),
name
=
"add_author"
),
path
(
'authors/add'
,
AuthorAddListView
.
as_view
(),
name
=
"add_author"
),
# for Books page
path
(
'books/'
,
BookListView
.
as_view
(),
name
=
'books'
),
path
(
'books/<int:pk>/details'
,
BookDetailView
.
as_view
(),
name
=
'book_detail'
),
path
(
'books/add'
,
BookAddListView
.
as_view
(),
name
=
"add_book"
)
path
(
'books/add'
,
BookAddListView
.
as_view
(),
name
=
"add_book"
),
path
(
'books/<int:pk>/edit'
,
BookEditView
.
as_view
(),
name
=
'book_edit'
)
]
\ No newline at end of file
Deokhyun_Lee_reading/bookshelf/views.py
View file @
8f7b159e
from
django.views
import
View
from
django.shortcuts
import
render
,
redirect
from
django.views.generic
import
ListView
,
DetailView
,
CreateView
from
django.views.generic
import
ListView
,
DetailView
,
CreateView
,
UpdateView
from
django.shortcuts
import
render
from
.models
import
Author
,
Book
from
.forms
import
AddBookForm
,
AddAuthorForm
...
...
@@ -56,6 +56,23 @@ class BookAddListView(CreateView):
return
redirect
(
'book_detail'
,
pk
=
new_book
.
pk
)
else
:
return
render
(
request
,
'book_details.html'
,
{
'form'
:
form
})
class
BookEditView
(
UpdateView
):
model
=
Book
form_class
=
AddBookForm
template_name
=
'books/edit-book.html'
def
post
(
self
,
request
,
pk
):
form
=
AddBookForm
(
request
.
POST
)
if
form
.
is_valid
():
# onSave is called, the form will have essential data and this includes pk as well.
new_book
=
form
.
save
()
# pass the pk and redirect.
return
redirect
(
'book_detail'
,
pk
=
new_book
.
pk
)
else
:
return
render
(
request
,
'book_details.html'
,
{
'form'
:
form
})
class
AuthorAddListView
(
CreateView
):
model
=
Author
...
...
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