Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
E
ejmejilla_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
EJ Mejilla
ejmejilla_reading
Commits
35dca3f6
Commit
35dca3f6
authored
Apr 25, 2023
by
EJ Mejilla
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added form pages for author and book creation.
Added hyperlinks to the form pages
parent
1e815aff
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
112 additions
and
6 deletions
+112
-6
forms.py
ejmejilla_reading/bookshelf/forms.py
+24
-0
author_form.html
...la_reading/bookshelf/templates/bookshelf/author_form.html
+21
-0
authors_form.html
...a_reading/bookshelf/templates/bookshelf/authors_form.html
+0
-0
books_form.html
...lla_reading/bookshelf/templates/bookshelf/books_form.html
+21
-0
home.html
ejmejilla_reading/bookshelf/templates/bookshelf/home.html
+4
-1
urls.py
ejmejilla_reading/bookshelf/urls.py
+13
-5
views.py
ejmejilla_reading/bookshelf/views.py
+29
-0
No files found.
ejmejilla_reading/bookshelf/forms.py
0 → 100644
View file @
35dca3f6
from
django
import
forms
from
.models
import
Books
,
Author
class
AuthorForm
(
forms
.
ModelForm
):
class
Meta
:
model
=
Author
fields
=
[
'first_name'
,
'last_name'
,
'age'
,
'nationality'
,
'bio'
]
class
BooksForm
(
forms
.
ModelForm
):
class
Meta
:
model
=
Books
fields
=
[
'title'
,
'author'
,
'publisher'
,
'year_published'
,
'ISBN'
,
'blurb'
]
ejmejilla_reading/bookshelf/templates/bookshelf/author_form.html
0 → 100644
View file @
35dca3f6
{% extends 'base.html' %}
{% load static %}
{% block title %} Add New Author {% endblock %}
{% block content %}
<div
class=
"form"
>
<form
action=
""
method=
"post"
>
{% csrf_token %}
<table>
{{ form.as_table }}
</table>
<input
type=
"submit"
value=
"Submit"
/>
</form>
</div>
<ul
class=
"footer"
>
<li><a
href=
"{% url 'bookshelf:home' %}"
>
Home
</a></li>
<li><a
href=
"{% url 'bookshelf:authors' %}"
>
Authors
</a></li>
<li><a
href=
"{% url 'bookshelf:books' %}"
>
Books
</a></li>
</ul>
{% endblock %}
ejmejilla_reading/bookshelf/templates/bookshelf/authors_form.html
0 → 100644
View file @
35dca3f6
ejmejilla_reading/bookshelf/templates/bookshelf/books_form.html
0 → 100644
View file @
35dca3f6
{% extends 'base.html' %}
{% load static %}
{% block title %} Add New Book {% endblock %}
{% block content %}
<div
class=
"form"
>
<form
action=
""
method=
"post"
>
{% csrf_token %}
<table>
{{ form.as_table }}
</table>
<input
type=
"submit"
value=
"Submit"
/>
</form>
</div>
<ul
class=
"footer"
>
<li><a
href=
"{% url 'bookshelf:home' %}"
>
Home
</a></li>
<li><a
href=
"{% url 'bookshelf:authors' %}"
>
Authors
</a></li>
<li><a
href=
"{% url 'bookshelf:books' %}"
>
Books
</a></li>
</ul>
{% endblock %}
ejmejilla_reading/bookshelf/templates/bookshelf/home.html
View file @
35dca3f6
...
...
@@ -11,5 +11,8 @@
<li><a
href=
"{% url 'bookshelf:books' %}"
>
Books
</a></li>
<li><a
href=
"{% url 'bookshelf:authors' %}"
>
Authors
</a></li>
</ul>
<ul
class=
"footer"
>
<li><a
href=
"{% url 'bookshelf:book-create' %}"
>
Add Books
</a></li>
<li><a
href=
"{% url 'bookshelf:author-create' %}"
>
Add Authors
</a></li>
</ul>
{% endblock %}
ejmejilla_reading/bookshelf/urls.py
View file @
35dca3f6
# bookshelf/urls.py
from
django.urls
import
path
from
.views
import
home_view
,
BookDetailView
,
BookListView
,
AuthorDetailView
,
AuthorListView
from
.views
import
(
home_view
,
BookDetailView
,
BookListView
,
AuthorDetailView
,
AuthorListView
,
AuthorCreateView
,
AuthorUpdateView
,
BooksCreateView
,
BooksUpdateView
)
urlpatterns
=
[
path
(
''
,
home_view
,
name
=
'home'
),
path
(
'books/'
,
BookListView
.
as_view
(
template_name
=
'bookshelf/books.html'
),
name
=
'books'
),
path
(
'books/<int:pk>/details/'
,
BookDetailView
.
as_view
(
template_name
=
"bookshelf/book_details.html"
),
name
=
'book-details'
),
path
(
'authors/'
,
AuthorListView
.
as_view
(
template_name
=
'bookshelf/authors.html'
),
name
=
'authors'
),
path
(
'authors/<int:pk>/details/'
,
AuthorDetailView
.
as_view
(
template_name
=
'bookshelf/author_details.html'
),
name
=
'author-details'
),
path
(
'books/'
,
BookListView
.
as_view
(),
name
=
'books'
),
path
(
'books/<int:pk>/details/'
,
BookDetailView
.
as_view
(),
name
=
'book-details'
),
path
(
'books/add'
,
BooksCreateView
.
as_view
(),
name
=
'book-create'
),
path
(
'books/<int:pk>'
,
BooksUpdateView
.
as_view
(),
name
=
'book-update'
),
path
(
'authors/'
,
AuthorListView
.
as_view
(),
name
=
'authors'
),
path
(
'authors/<int:pk>/details/'
,
AuthorDetailView
.
as_view
(),
name
=
'author-details'
),
path
(
'authors/add'
,
AuthorCreateView
.
as_view
(),
name
=
'author-create'
),
path
(
'authors/<int:pk>'
,
BooksUpdateView
.
as_view
(),
name
=
'author-update'
),
]
app_name
=
"bookshelf"
ejmejilla_reading/bookshelf/views.py
View file @
35dca3f6
...
...
@@ -3,8 +3,10 @@ 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
,
BooksForm
def
home_view
(
request
):
return
render
(
request
,
'bookshelf/home.html'
)
...
...
@@ -12,15 +14,42 @@ def home_view(request):
class
BookDetailView
(
DetailView
):
model
=
Books
template_name
=
"bookshelf/book_details.html"
class
BookListView
(
ListView
):
model
=
Books
template_name
=
'bookshelf/books.html'
class
AuthorDetailView
(
DetailView
):
model
=
Author
template_name
=
'bookshelf/author_details.html'
class
AuthorListView
(
ListView
):
model
=
Author
template_name
=
'bookshelf/authors.html'
class
AuthorCreateView
(
CreateView
):
model
=
Author
fields
=
'__all__'
class
AuthorUpdateView
(
UpdateView
):
model
=
Author
fields
=
'__all__'
template_name
=
'author_details.html'
class
BooksCreateView
(
CreateView
):
model
=
Books
fields
=
'__all__'
class
BooksUpdateView
(
UpdateView
):
model
=
Books
fields
=
'__all__'
template_name
=
'book_details.html'
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