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
435723a9
Commit
435723a9
authored
Apr 27, 2023
by
Brendan Fausto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added UpdateView for Books and Authors, and respective templates
parent
54404855
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
113 additions
and
5 deletions
+113
-5
forms.cpython-311.pyc
reading/bookshelf/__pycache__/forms.cpython-311.pyc
+0
-0
urls.cpython-311.pyc
reading/bookshelf/__pycache__/urls.cpython-311.pyc
+0
-0
views.cpython-311.pyc
reading/bookshelf/__pycache__/views.cpython-311.pyc
+0
-0
forms.py
reading/bookshelf/forms.py
+1
-1
edit-author.html
reading/bookshelf/templates/bookshelf/edit-author.html
+40
-0
edit-book.html
reading/bookshelf/templates/bookshelf/edit-book.html
+40
-0
urls.py
reading/bookshelf/urls.py
+4
-1
views.py
reading/bookshelf/views.py
+28
-3
db.sqlite3
reading/db.sqlite3
+0
-0
No files found.
reading/bookshelf/__pycache__/forms.cpython-311.pyc
0 → 100644
View file @
435723a9
File added
reading/bookshelf/__pycache__/urls.cpython-311.pyc
View file @
435723a9
No preview for this file type
reading/bookshelf/__pycache__/views.cpython-311.pyc
View file @
435723a9
No preview for this file type
reading/bookshelf/forms.py
View file @
435723a9
...
@@ -8,6 +8,6 @@ class BookForm(ModelForm):
...
@@ -8,6 +8,6 @@ class BookForm(ModelForm):
class
AuthorForm
(
ModelForm
):
class
AuthorForm
(
ModelForm
):
class
Meta
:
class
Meta
:
model
=
Book
s
model
=
Author
s
fields
=
[
'first_name'
,
'last_name'
,
'age'
,
'nationality'
,
'bio'
]
fields
=
[
'first_name'
,
'last_name'
,
'age'
,
'nationality'
,
'bio'
]
\ No newline at end of file
reading/bookshelf/templates/bookshelf/edit-author.html
0 → 100644
View file @
435723a9
{% extends 'base.html' %}
{% block title %}
Edit Author
{% endblock %}
{% block header %}
<h1>
Edit Author
</h1>
{% endblock %}
{% block content %}
{{ form.non_field_errors }}
{% for field in form %}
{% if field.errors %}
<p>
{{ field.label }} has the following errors:
</p>
<ul>
{% for error in field.errors %}
<li>
{{ error }}
</li>
{% endfor %}
</ul>
{% endif %}
{% endfor %}
<form
method =
"POST"
>
{% csrf_token %}
{{ form.as_p }}
<input
type =
"submit"
value =
"Save Changes"
>
</form>
<p>
<a
href =
"http://127.0.0.1:8000/home"
>
Home
</a>
<a
href =
"http://127.0.0.1:8000/authors"
>
Authors
</a>
<a
href =
"http://127.0.0.1:8000/books"
>
Books
</a>
</p>
{% endblock %}
\ No newline at end of file
reading/bookshelf/templates/bookshelf/edit-book.html
0 → 100644
View file @
435723a9
{% extends 'base.html' %}
{% block title %}
Edit Book
{% endblock %}
{% block header %}
<h1>
Edit Book
</h1>
{% endblock %}
{% block content %}
{{ form.non_field_errors }}
{% for field in form %}
{% if field.errors %}
<p>
{{ field.label }} has the following errors:
</p>
<ul>
{% for error in field.errors %}
<li>
{{ error }}
</li>
{% endfor %}
</ul>
{% endif %}
{% endfor %}
<form
method =
"POST"
>
{% csrf_token %}
{{ form.as_p }}
<input
type =
"submit"
value =
"Save Changes"
>
</form>
<p>
<a
href =
"http://127.0.0.1:8000/home"
>
Home
</a>
<a
href =
"http://127.0.0.1:8000/authors"
>
Authors
</a>
<a
href =
"http://127.0.0.1:8000/books"
>
Books
</a>
</p>
{% endblock %}
\ No newline at end of file
reading/bookshelf/urls.py
View file @
435723a9
# about/urls.py
# about/urls.py
from
django.urls
import
path
from
django.urls
import
path
from
.views
import
(
home_view
,
AuthorListView
,
BookListView
,
BookDetailView
,
AuthorDetailView
,
BookCreateView
,
AuthorCreateView
)
from
.views
import
(
home_view
,
AuthorListView
,
BookListView
,
BookDetailView
,
AuthorDetailView
,
BookCreateView
,
AuthorCreateView
,
BookUpdateView
,
AuthorUpdateView
)
urlpatterns
=
[
urlpatterns
=
[
path
(
'home'
,
home_view
,
name
=
'index'
),
path
(
'home'
,
home_view
,
name
=
'index'
),
...
@@ -11,6 +12,8 @@ urlpatterns = [
...
@@ -11,6 +12,8 @@ urlpatterns = [
path
(
'authors/<int:pk>/details'
,
AuthorDetailView
.
as_view
(),
name
=
'authors-details'
),
path
(
'authors/<int:pk>/details'
,
AuthorDetailView
.
as_view
(),
name
=
'authors-details'
),
path
(
'books/add'
,
BookCreateView
.
as_view
(),
name
=
'books-create'
),
path
(
'books/add'
,
BookCreateView
.
as_view
(),
name
=
'books-create'
),
path
(
'authors/add'
,
AuthorCreateView
.
as_view
(),
name
=
'authors-create'
),
path
(
'authors/add'
,
AuthorCreateView
.
as_view
(),
name
=
'authors-create'
),
path
(
'books/<int:pk>/edit'
,
BookUpdateView
.
as_view
(),
name
=
'books-update'
),
path
(
'authors/<int:pk>/edit'
,
AuthorUpdateView
.
as_view
(),
name
=
'author-update'
),
]
]
app_name
=
"bookshelf"
# for proper namespacing in urls, otherwise will result in errors
app_name
=
"bookshelf"
# for proper namespacing in urls, otherwise will result in errors
\ No newline at end of file
reading/bookshelf/views.py
View file @
435723a9
...
@@ -2,16 +2,20 @@ from django.shortcuts import render
...
@@ -2,16 +2,20 @@ from django.shortcuts import render
from
django.views
import
View
from
django.views
import
View
from
django.views.generic.detail
import
DetailView
from
django.views.generic.detail
import
DetailView
from
django.views.generic.list
import
ListView
from
django.views.generic.list
import
ListView
from
django.views.generic.edit
import
UpdateView
from
django.shortcuts
import
get_object_or_404
from
django.shortcuts
import
get_object_or_404
from
django.views.generic.edit
import
CreateView
,
UpdateView
from
django.views.generic.edit
import
CreateView
,
UpdateView
from
.models
import
Books
,
Authors
from
.models
import
Books
,
Authors
from
.forms
import
BookForm
,
AuthorForm
def
home_view
(
request
):
def
home_view
(
request
):
return
render
(
request
,
'bookshelf/homepage.html'
,
{
return
render
(
request
,
'bookshelf/homepage.html'
,
{
'page_title'
:
"Books and Authors"
'page_title'
:
"Books and Authors"
})
})
class
AuthorListView
(
ListView
):
class
AuthorListView
(
ListView
):
def
get
(
self
,
request
):
def
get
(
self
,
request
):
authors
=
Authors
.
objects
.
all
()
authors
=
Authors
.
objects
.
all
()
...
@@ -19,6 +23,7 @@ class AuthorListView(ListView):
...
@@ -19,6 +23,7 @@ class AuthorListView(ListView):
'authors'
:
authors
'authors'
:
authors
})
})
class
BookListView
(
ListView
):
class
BookListView
(
ListView
):
def
get
(
self
,
request
):
def
get
(
self
,
request
):
books
=
Books
.
objects
.
all
()
books
=
Books
.
objects
.
all
()
...
@@ -26,6 +31,7 @@ class BookListView(ListView):
...
@@ -26,6 +31,7 @@ class BookListView(ListView):
'books'
:
books
'books'
:
books
})
})
class
BookDetailView
(
DetailView
):
class
BookDetailView
(
DetailView
):
model
=
Books
model
=
Books
template_name
=
'bookshelf/books_details.html'
template_name
=
'bookshelf/books_details.html'
...
@@ -34,17 +40,36 @@ class BookDetailView(DetailView):
...
@@ -34,17 +40,36 @@ class BookDetailView(DetailView):
print
(
"BooksDetailView is being called"
)
print
(
"BooksDetailView is being called"
)
return
super
()
.
get
(
request
,
*
args
,
**
kwargs
)
return
super
()
.
get
(
request
,
*
args
,
**
kwargs
)
class
AuthorDetailView
(
DetailView
):
class
AuthorDetailView
(
DetailView
):
model
=
Authors
model
=
Authors
template_name
=
'bookshelf/authors_details.html'
template_name
=
'bookshelf/authors_details.html'
class
BookCreateView
(
CreateView
):
class
BookCreateView
(
CreateView
):
model
=
Books
model
=
Books
fields
=
'__all__'
fields
=
'__all__'
template_name
=
'add-book.html'
template_name
=
'bookshelf/add-book.html'
class
AuthorCreateView
(
CreateView
):
class
AuthorCreateView
(
CreateView
):
model
=
Book
s
model
=
Author
s
fields
=
'__all__'
fields
=
'__all__'
template_name
=
'add-book.html'
template_name
=
'bookshelf/add-author.html'
class
BookUpdateView
(
UpdateView
):
model
=
Books
form_class
=
BookForm
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
form_class
=
AuthorEditForm
template_name
=
'bookshelf/edit-author.html'
def
get_success_url
(
self
):
return
reverse_lazy
(
'author_details'
,
kwargs
=
{
'pk'
:
self
.
object
.
pk
})
# Create your views here.
# Create your views here.
reading/db.sqlite3
View file @
435723a9
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