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
2febbdca
Commit
2febbdca
authored
Mar 28, 2023
by
Fritzie Dianne Del Pilar
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Modified contents
parent
34ba7650
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
35 additions
and
7 deletions
+35
-7
views.py
diannedelpilar_reading/bookshelf/views.py
+35
-7
No files found.
diannedelpilar_reading/bookshelf/views.py
View file @
2febbdca
from
django.shortcuts
import
render
from
django.http
import
HttpResponse
from
django.http
import
HttpResponse
,
Http404
from
.models
import
Author
,
Book
from
django.views
import
View
def
index
(
request
):
bookshelf_view
=
"Widget's Announcement Board <br/>"
author
=
Author
.
objects
.
all
()
book
=
Book
.
objects
.
all
()
return
HttpResponse
(
bookshelf_view
)
def
home
(
request
):
return
render
(
request
,
"bookshelf/home.html"
)
class
BooksView
(
View
):
def
get
(
self
,
request
):
books_list
=
Book
.
objects
.
all
()
.
order_by
(
"title"
)
return
render
(
request
,
"bookshelf/books.html"
,
{
"books_list"
:
books_list
})
class
BooksDetailView
(
View
):
def
get
(
self
,
request
,
book_id
):
try
:
book
=
Book
.
objects
.
get
(
pk
=
book_id
)
except
Book
.
DoesNotExist
:
raise
Http404
(
"Book does not exist!"
)
return
render
(
request
,
"bookshelf/book_detail.html"
,
{
"book"
:
book
})
class
AuthorsView
(
View
):
def
get
(
self
,
request
):
authors_list
=
Author
.
objects
.
all
()
.
order_by
(
"first_name"
)
return
render
(
request
,
"bookshelf/authors.html"
,
{
"authors_list"
:
authors_list
})
class
AuthorsDetailView
(
View
):
def
get
(
self
,
request
,
author_id
):
try
:
author
=
Author
.
objects
.
get
(
pk
=
author_id
)
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
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