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
2c6d6082
Commit
2c6d6082
authored
Apr 25, 2023
by
Deokhyun Lee
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixed view CBV and it displays the form correctly. Need to implement the submit button
parent
295a0ad7
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
6 additions
and
17 deletions
+6
-17
add-book.html
Deokhyun_Lee_reading/bookshelf/templates/books/add-book.html
+1
-0
views.py
Deokhyun_Lee_reading/bookshelf/views.py
+5
-17
No files found.
Deokhyun_Lee_reading/bookshelf/templates/books/add-book.html
View file @
2c6d6082
...
...
@@ -2,6 +2,7 @@
{% block title %}
Add New Book
{% endblock %}
{% block content %}
<form
method=
"post"
>
{% csrf_token %}
...
...
Deokhyun_Lee_reading/bookshelf/views.py
View file @
2c6d6082
from
django.views
import
View
from
django.views.generic
import
ListView
,
DetailView
from
django.views.generic
import
ListView
,
DetailView
,
CreateView
from
django.shortcuts
import
render
from
.models
import
Author
,
Books
from
.forms
import
AddBookForm
...
...
@@ -41,19 +41,7 @@ class BookDetailView(DetailView):
template_name
=
'books/book_details.html'
context_object_name
=
'book'
class
BookAddListView
(
ListView
):
template_name
=
'add-book.html'
form_class
=
AddBookForm
def
form_valid
(
self
,
form
):
# Create a new book object with the form data
new_book
=
Books
.
objects
.
create
(
title
=
form
.
cleaned_data
[
'title'
],
author
=
form
.
cleaned_data
[
'author'
],
publisher
=
form
.
cleaned_data
[
'publisher'
],
year_published
=
form
.
cleaned_data
[
'year_published'
],
ISBN
=
form
.
cleaned_data
[
'ISBN'
],
blurb
=
form
.
cleaned_data
[
'blurb'
]
)
# Redirect the user to the list of books
return
super
()
.
form_valid
(
form
)
class
BookAddListView
(
CreateView
):
model
=
Books
fields
=
[
'title'
,
'author'
,
'publisher'
,
'year_published'
,
'ISBN'
,
'blurb'
]
template_name
=
"books/add-book.html"
\ No newline at end of file
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