Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
J
janang_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
Jan Ericsson Ong Ang
janang_reading
Commits
fa5ac0e4
Commit
fa5ac0e4
authored
Apr 25, 2023
by
Jan Ericsson Ong Ang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
edited the 4 new html files for the forms to work
parent
a0de761a
Changes
11
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
59 additions
and
51 deletions
+59
-51
forms.cpython-310.pyc
janang_reading/bookshelf/__pycache__/forms.cpython-310.pyc
+0
-0
models.cpython-310.pyc
janang_reading/bookshelf/__pycache__/models.cpython-310.pyc
+0
-0
urls.cpython-310.pyc
janang_reading/bookshelf/__pycache__/urls.cpython-310.pyc
+0
-0
views.cpython-310.pyc
janang_reading/bookshelf/__pycache__/views.cpython-310.pyc
+0
-0
add-author.html
janang_reading/bookshelf/templates/bookshelf/add-author.html
+5
-5
add-book.html
janang_reading/bookshelf/templates/bookshelf/add-book.html
+6
-6
author_details.html
...reading/bookshelf/templates/bookshelf/author_details.html
+3
-3
edit-author.html
...ng_reading/bookshelf/templates/bookshelf/edit-author.html
+5
-5
edit-book.html
janang_reading/bookshelf/templates/bookshelf/edit-book.html
+6
-6
urls.py
janang_reading/bookshelf/urls.py
+5
-5
views.py
janang_reading/bookshelf/views.py
+29
-21
No files found.
janang_reading/bookshelf/__pycache__/forms.cpython-310.pyc
View file @
fa5ac0e4
No preview for this file type
janang_reading/bookshelf/__pycache__/models.cpython-310.pyc
View file @
fa5ac0e4
No preview for this file type
janang_reading/bookshelf/__pycache__/urls.cpython-310.pyc
View file @
fa5ac0e4
No preview for this file type
janang_reading/bookshelf/__pycache__/views.cpython-310.pyc
View file @
fa5ac0e4
No preview for this file type
janang_reading/bookshelf/templates/bookshelf/add-author.html
View file @
fa5ac0e4
...
...
@@ -7,15 +7,15 @@
<form
method=
"post"
>
{% csrf_token %}
<label>
First Name:
</label>
<input
id=
"first_name"
type=
"text"
name=
"first_name"
max
length=
"50"
/>
<input
id=
"first_name"
type=
"text"
name=
"first_name"
max
length=
"50"
/>
<br>
<label>
Last Name:
</label>
<input
id=
"last_name"
type=
"text"
name=
"last_name"
max
length=
"100"
/>
<input
id=
"last_name"
type=
"text"
name=
"last_name"
max
length=
"100"
/>
<br>
<label>
Age:
</label>
<input
id=
"age"
type=
"number"
name=
"age"
/>
<input
id=
"age"
type=
"number"
name=
"age"
/>
<br>
<label>
Nationality:
</label>
<input
id=
"nationality"
type=
"text"
name=
"nationality"
/>
<input
id=
"nationality"
type=
"text"
name=
"nationality"
/>
<br>
<label>
Bio:
</label>
<input
id=
"bio"
type=
"text"
name=
"bio"
/>
<input
id=
"bio"
type=
"text"
name=
"bio"
/>
<br>
</form>
<button
type=
"button"
>
...
...
janang_reading/bookshelf/templates/bookshelf/add-book.html
View file @
fa5ac0e4
...
...
@@ -7,17 +7,17 @@
<form
method=
"post"
>
{% csrf_token %}
<label>
Title:
</label>
<input
id=
"title"
type=
"text"
name=
"title"
max
length=
"50"
/>
<input
id=
"title"
type=
"text"
name=
"title"
max
length=
"50"
/>
<br>
<label>
Author:
</label>
<input
id=
"author"
type=
"text"
name=
"author"
max
length=
"100"
/>
<input
id=
"author"
type=
"text"
name=
"author"
max
length=
"100"
/>
<br>
<label>
Publisher:
</label>
<input
id=
"publisher"
type=
"text"
name=
"publisher"
/>
<input
id=
"publisher"
type=
"text"
name=
"publisher"
/>
<br>
<label>
Year Published:
</label>
<input
id=
"year_published"
type=
"number"
name=
"year_published"
/>
<input
id=
"year_published"
type=
"number"
name=
"year_published"
/>
<br>
<label>
ISBN:
</label>
<input
id=
"ISBN"
type=
"number"
name=
"ISBN"
/>
<input
id=
"ISBN"
type=
"number"
name=
"ISBN"
/>
<br>
<label>
Blurb:
</label>
<input
id=
"blurb"
type=
"text"
name=
"blurb"
/>
<input
id=
"blurb"
type=
"text"
name=
"blurb"
/>
<br>
</form>
<button
type=
"button"
>
...
...
janang_reading/bookshelf/templates/bookshelf/author_details.html
View file @
fa5ac0e4
...
...
@@ -10,15 +10,15 @@
<p>
{{ author.bio }}
</p>
<button
type=
"button"
>
<a
href=
"/bookshelf/
books/{{ book
.id }}/edit/"
>
Edit
Book
<a
href=
"/bookshelf/
authors/{{ author
.id }}/edit/"
>
Edit
Author
</a>
</button><br>
<p>
Books by {{ author.first_name }} {{ author.last_name }} I love
</p>
{% for authbook in author.books_set.all %}
<a
href=
"/bookshelf/
author
s/{{ authbook.id }}/details/"
>
{{ authbook }}
<br></a>
<a
href=
"/bookshelf/
book
s/{{ authbook.id }}/details/"
>
{{ authbook }}
<br></a>
{% endfor %}
<br>
...
...
janang_reading/bookshelf/templates/bookshelf/edit-author.html
View file @
fa5ac0e4
...
...
@@ -7,15 +7,15 @@
<form
method=
"post"
>
{% csrf_token %}
<label>
First Name:
</label>
<input
id=
"first_name"
type=
"text"
name=
"first_name"
max
length=
"50"
/>
<input
id=
"first_name"
type=
"text"
name=
"first_name"
max
length=
"50"
/>
<br>
<label>
Last Name:
</label>
<input
id=
"last_name"
type=
"text"
name=
"last_name"
max
length=
"100"
/>
<input
id=
"last_name"
type=
"text"
name=
"last_name"
max
length=
"100"
/>
<br>
<label>
Age:
</label>
<input
id=
"age"
type=
"number"
name=
"age"
/>
<input
id=
"age"
type=
"number"
name=
"age"
/>
<br>
<label>
Nationality:
</label>
<input
id=
"nationality"
type=
"text"
name=
"nationality"
/>
<input
id=
"nationality"
type=
"text"
name=
"nationality"
/>
<br>
<label>
Bio:
</label>
<input
id=
"bio"
type=
"text"
name=
"bio"
/>
<input
id=
"bio"
type=
"text"
name=
"bio"
/>
<br>
</form>
<button
type=
"button"
>
...
...
janang_reading/bookshelf/templates/bookshelf/edit-book.html
View file @
fa5ac0e4
...
...
@@ -7,17 +7,17 @@
<form
method=
"post"
>
{% csrf_token %}
<label>
Title:
</label>
<input
id=
"title"
type=
"text"
name=
"title"
max
length=
"50"
/>
<input
id=
"title"
type=
"text"
name=
"title"
max
length=
"50"
/>
<br>
<label>
Author:
</label>
<input
id=
"author"
type=
"text"
name=
"author"
max
length=
"100"
/>
<input
id=
"author"
type=
"text"
name=
"author"
max
length=
"100"
/>
<br>
<label>
Publisher:
</label>
<input
id=
"publisher"
type=
"text"
name=
"publisher"
/>
<input
id=
"publisher"
type=
"text"
name=
"publisher"
/>
<br>
<label>
Year Published:
</label>
<input
id=
"year_published"
type=
"number"
name=
"year_published"
/>
<input
id=
"year_published"
type=
"number"
name=
"year_published"
/>
<br>
<label>
ISBN:
</label>
<input
id=
"ISBN"
type=
"number"
name=
"ISBN"
/>
<input
id=
"ISBN"
type=
"number"
name=
"ISBN"
/>
<br>
<label>
Blurb:
</label>
<input
id=
"blurb"
type=
"text"
name=
"blurb"
/>
<input
id=
"blurb"
type=
"text"
name=
"blurb"
/>
<br>
</form>
<button
type=
"button"
>
...
...
janang_reading/bookshelf/urls.py
View file @
fa5ac0e4
from
django.urls
import
path
from
.
import
views
from
.views
import
HomeView
,
AuthorView
,
AuthorDetailView
,
BooksView
,
BookDetailView
from
.views
import
HomeView
,
AuthorView
,
AuthorDetailView
,
BooksView
,
BookDetailView
,
AuthorCreateView
,
AuthorUpdateView
,
BooksCreateView
,
BooksUpdateView
# url for bookshelf
...
...
@@ -8,12 +8,12 @@ urlpatterns = [
path
(
''
,
views
.
HomeView
,
name
=
'home'
),
path
(
'authors/'
,
AuthorView
.
as_view
(),
name
=
'authors'
),
path
(
'authors/<int:id>/details/'
,
AuthorDetailView
.
as_view
(),
name
=
'author-detail'
),
path
(
'authors/<int:id>/add/'
,
Author
Detail
View
.
as_view
(),
name
=
'add-author'
),
path
(
'authors/<int:id>/edit/'
,
Author
Detail
View
.
as_view
(),
name
=
'edit-author'
),
path
(
'authors/<int:id>/add/'
,
Author
Create
View
.
as_view
(),
name
=
'add-author'
),
path
(
'authors/<int:id>/edit/'
,
Author
Update
View
.
as_view
(),
name
=
'edit-author'
),
path
(
'books/'
,
BooksView
.
as_view
(),
name
=
'books'
),
path
(
'books/<int:id>/details/'
,
BookDetailView
.
as_view
(),
name
=
'books-detail'
),
path
(
'books/<int:id>/add/'
,
Book
Detail
View
.
as_view
(),
name
=
'add-book'
),
path
(
'books/<int:id>/edit/'
,
Book
Detail
View
.
as_view
(),
name
=
'edit-book'
),
path
(
'books/<int:id>/add/'
,
Book
sCreate
View
.
as_view
(),
name
=
'add-book'
),
path
(
'books/<int:id>/edit/'
,
Book
sUpdate
View
.
as_view
(),
name
=
'edit-book'
),
]
app_name
=
'bookshelf'
\ No newline at end of file
janang_reading/bookshelf/views.py
View file @
fa5ac0e4
...
...
@@ -2,8 +2,9 @@ from django.shortcuts import render
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
CreateView
,
UpdateView
from
.models
import
Author
,
Books
from
.
forms
import
AuthorForm
,
BookForm
from
.forms
import
AuthorForm
,
BookForm
# Create your views here.
...
...
@@ -12,23 +13,26 @@ def HomeView(request):
return
render
(
request
,
'bookshelf/home.html'
,
{
'nickname'
:
'Jan'
})
#CBV
#Author
class
AuthorView
(
ListView
):
pk_url_kwarg
=
'id'
model
=
Author
queryset
=
Author
.
objects
.
all
()
def
get
(
self
,
request
):
author_data
=
Author
.
objects
.
all
()
.
values
()
return
render
(
request
,
'bookshelf/authors.html'
,
{
'nickname'
:
'Jan'
,
'author_data'
:
author_data
})
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
():
return
self
.
get
(
request
,
*
args
,
**
kwargs
)
else
:
return
render
(
request
,
'bookshelf/author_details.html'
,
{
'form'
:
form
})
class
AuthorCreateView
(
CreateView
):
pk_url_kwarg
=
'id'
model
=
Author
fields
=
"__all__"
template_name
=
'bookshelf/add-author.html'
class
AuthorUpdateView
(
UpdateView
):
pk_url_kwarg
=
'id'
model
=
Author
fields
=
"__all__"
template_name
=
'bookshelf/edit-author.html'
class
AuthorDetailView
(
DetailView
):
pk_url_kwarg
=
'id'
...
...
@@ -37,22 +41,26 @@ class AuthorDetailView(DetailView):
template_name
=
'bookshelf/author_details.html'
context_object_name
=
'author'
#Books
class
BooksView
(
ListView
):
pk_url_kwarg
=
'id'
model
=
Books
queryset
=
Books
.
objects
.
all
()
def
get
(
self
,
request
):
book_data
=
Books
.
objects
.
all
()
.
values
()
return
render
(
request
,
'bookshelf/books.html'
,
{
'nickname'
:
'Jan'
,
'book_data'
:
book_data
})
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
():
return
self
.
get
(
request
,
*
args
,
**
kwargs
)
else
:
return
render
(
request
,
'bookshelf/book_details.html'
,
{
'form'
:
form
})
class
BooksCreateView
(
CreateView
):
pk_url_kwarg
=
'id'
model
=
Books
fields
=
"__all__"
template_name
=
'bookshelf/add-book.html'
class
BooksUpdateView
(
UpdateView
):
pk_url_kwarg
=
'id'
model
=
Books
fields
=
"__all__"
template_name
=
'bookshelf/edit-book.html'
class
BookDetailView
(
DetailView
):
pk_url_kwarg
=
'id'
...
...
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