Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
F
fausto_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
Brendan Fausto
fausto_reading
Commits
3374e0f4
Commit
3374e0f4
authored
Apr 27, 2023
by
Brendan Fausto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
defined authorview and bookview to fix error in Book-Edit and Author-Edit
parent
435723a9
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
24 additions
and
7 deletions
+24
-7
views.cpython-311.pyc
reading/bookshelf/__pycache__/views.cpython-311.pyc
+0
-0
views.py
reading/bookshelf/views.py
+24
-7
db.sqlite3
reading/db.sqlite3
+0
-0
No files found.
reading/bookshelf/__pycache__/views.cpython-311.pyc
View file @
3374e0f4
No preview for this file type
reading/bookshelf/views.py
View file @
3374e0f4
from
django.shortcuts
import
render
from
django.shortcuts
import
render
,
redirect
from
django.views
import
View
from
django.views.generic.detail
import
DetailView
from
django.views.generic.list
import
ListView
from
django.views.generic.edit
import
UpdateView
from
django.shortcuts
import
get_object_or_404
from
django.views.generic.edit
import
CreateView
,
UpdateView
from
django.forms
import
formset_factory
,
BaseFormSet
,
HiddenInput
,
modelform_factory
from
django.http
import
HttpResponse
from
.models
import
Books
,
Authors
from
.forms
import
BookForm
,
AuthorForm
...
...
@@ -60,16 +62,31 @@ class AuthorCreateView(CreateView):
class
BookUpdateView
(
UpdateView
):
model
=
Books
f
orm_class
=
BookForm
f
ields
=
'__all__'
template_name
=
'bookshelf/edit-book.html'
def
get_success_url
(
self
):
return
reverse_lazy
(
'books_details'
,
kwargs
=
{
'pk'
:
self
.
object
.
pk
})
class
AuthorUpdateView
(
UpdateView
):
model
=
Authors
f
orm_class
=
AuthorEditForm
f
ields
=
'__all__'
template_name
=
'bookshelf/edit-author.html'
def
get_success_url
(
self
):
return
reverse_lazy
(
'author_details'
,
kwargs
=
{
'pk'
:
self
.
object
.
pk
})
def
book_view
(
request
):
book
=
Books
.
object
.
get
(
pk
=
self
.
object
.
pk
)
if
request
.
method
==
'POST'
:
form
=
BookForm
(
request
.
POST
,
instance
=
book
)
form
.
save
()
BookModelFormFactory
=
modelform_factory
(
Books
,
fields
=
'__all__'
)
form
=
BookModelFormFactory
()
return
render
(
request
,
'bookshelf/edit-book.html'
,{
'form'
:
form
})
def
author_view
(
request
):
author
=
Authors
.
object
.
get
(
pk
=
self
.
object
.
pk
)
if
request
.
method
==
'POST'
:
form
=
AuthorForm
(
request
.
POST
,
instance
=
author
)
form
.
save
()
AuthorModelFormFactory
=
modelform_factory
(
Authors
,
fields
=
'__all__'
)
form
=
AuthorModelFormFactory
()
return
render
(
request
,
'bookshelf/edit-author.html'
,
{
'form'
:
form
})
# Create your views here.
reading/db.sqlite3
View file @
3374e0f4
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