Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
D
diannedelpilar_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
Fritzie Dianne Del Pilar
diannedelpilar_reading
Commits
bdade45c
Commit
bdade45c
authored
Apr 25, 2023
by
Fritzie Dianne Del Pilar
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added imports and some classes for add and edit
parent
45c7a902
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
53 additions
and
3 deletions
+53
-3
views.py
diannedelpilar_reading/bookshelf/views.py
+53
-3
No files found.
diannedelpilar_reading/bookshelf/views.py
View file @
bdade45c
from
django.shortcuts
import
render
from
django.http
import
Http
Response
,
Http
404
from
django.shortcuts
import
render
,
reverse
from
django.http
import
Http404
from
.models
import
Author
,
Book
from
django.views
import
View
from
.forms
import
BookForm
,
AuthorForm
from
django.shortcuts
import
get_object_or_404
from
django.views.generic.edit
import
UpdateView
def
home
(
request
):
return
render
(
request
,
"bookshelf/home.html"
)
...
...
@@ -35,4 +39,50 @@ class AuthorsDetailView(View):
except
Author
.
DoesNotExist
:
raise
Http404
(
"Author does not exist!"
)
books_list
=
Book
.
objects
.
all
()
.
filter
(
author
=
author
)
return
render
(
request
,
"bookshelf/author_detail.html"
,
{
"author"
:
author
,
"books_list"
:
books_list
})
\ No newline at end of file
return
render
(
request
,
"bookshelf/author_detail.html"
,
{
"author"
:
author
,
"books_list"
:
books_list
})
class
AddBookView
(
View
):
model
=
Book
def
get_context_data
(
self
,
**
kwargs
):
context
=
super
()
.
get_context_data
(
**
kwargs
)
context
[
'form'
]
=
BookForm
()
return
context
def
post
(
self
,
request
,
*
args
,
**
kwargs
):
form
=
BookForm
(
request
.
POST
)
if
form
.
is_valid
():
new_book
=
form
.
save
()
return
render
(
request
,
"bookshelf/book_detail.html"
,
{
'book'
:
new_book
})
else
:
return
render
(
request
,
"bookshelf/add-book.html"
,
{
'form'
:
form
})
class
AddAuthorView
(
View
):
model
=
Author
def
get_context_data
(
self
,
**
kwargs
):
context
=
super
()
.
get_context_data
(
**
kwargs
)
context
[
'form'
]
=
AuthorForm
()
return
context
def
post
(
self
,
request
,
*
args
,
**
kwargs
):
form
=
AuthorForm
(
request
.
POST
)
if
form
.
is_valid
():
new_author
=
form
.
save
()
return
render
(
request
,
"bookshelf/author_detail.html"
,
{
'author'
:
new_author
})
else
:
return
render
(
request
,
"bookshelf/add-author.html"
,
{
'form'
:
form
})
class
BookEditView
(
UpdateView
):
model
=
Book
fields
=
'__all__'
template_name
=
'bookshelf/edit-book.html'
def
get_success_url
(
self
):
return
reverse
(
'bookshelf:book_detail'
,
kwargs
=
{
'book_id'
:
self
.
object
.
pk
})
class
AuthorEditView
(
UpdateView
):
model
=
Author
fields
=
'__all__'
template_name
=
'bookshelf/edit-author.html'
def
get_success_url
(
self
):
return
reverse
(
'bookshelf:author_detail'
,
kwargs
=
{
'author_id'
:
self
.
object
.
pk
})
\ 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