Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
D
danielramos_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
John Riz Daniel Ramos
danielramos_reading
Commits
f25f109b
Commit
f25f109b
authored
Apr 25, 2023
by
John Riz Daniel Ramos
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add Book Function
+ Finished Add Book Functionality
parent
7fa2cc8c
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
71 additions
and
8 deletions
+71
-8
forms.py
danielramos_reading/bookshelf/forms.py
+12
-0
urls.py
danielramos_reading/bookshelf/urls.py
+2
-1
views.py
danielramos_reading/bookshelf/views.py
+27
-5
db.sqlite3
danielramos_reading/db.sqlite3
+0
-0
add-book.html
danielramos_reading/templates/bookshelf/add-book.html
+2
-2
book_details.html
danielramos_reading/templates/bookshelf/book_details.html
+6
-0
edit-book.html
danielramos_reading/templates/bookshelf/edit-book.html
+22
-0
No files found.
danielramos_reading/bookshelf/forms.py
0 → 100644
View file @
f25f109b
from
django
import
forms
from
.models
import
Books
,
Author
class
BooksForm
(
forms
.
ModelForm
):
class
Meta
:
model
=
Books
fields
=
'__all__'
class
BooksForm
(
forms
.
ModelForm
):
class
Meta
:
model
=
Author
fields
=
'__all__'
\ No newline at end of file
danielramos_reading/bookshelf/urls.py
View file @
f25f109b
...
...
@@ -5,8 +5,9 @@ from .views import home_view, BooksListView, BooksDetailView, AuthorsView, Autho
urlpatterns
=
[
path
(
'home/'
,
home_view
,
name
=
'home_view'
),
path
(
'books/'
,
BooksListView
.
as_view
(),
name
=
'books-list'
),
path
(
'books/add'
,
BooksCreateView
.
as_view
(),
name
=
'books-create'
),
path
(
'books/<int:pk>/details/'
,
BooksDetailView
.
as_view
(),
name
=
'books-detail'
),
path
(
'books/add/'
,
BooksCreateView
.
as_view
(),
name
=
'books-add'
),
path
(
'books/<int:pk>/edit/'
,
BooksUpdateView
.
as_view
(),
name
=
'books-add'
),
path
(
'authors/'
,
AuthorsView
.
as_view
(),
name
=
'authors-list'
),
path
(
'authors/<int:pk>/details/'
,
AuthorsDetailView
.
as_view
(),
name
=
'authors-detail'
),
]
...
...
danielramos_reading/bookshelf/views.py
View file @
f25f109b
from
django.shortcuts
import
render
from
django.shortcuts
import
render
,
redirect
from
django.http.response
import
HttpResponseRedirect
from
django.views.generic.list
import
ListView
from
django.views.generic.detail
import
DetailView
from
django.views.generic.edit
import
CreateView
,
UpdateView
from
.models
import
Author
,
Books
from
.forms
import
BooksForm
def
home_view
(
request
):
...
...
@@ -17,7 +19,7 @@ class BooksListView(ListView):
class
BooksDetailView
(
DetailView
):
model
=
Books
template_name
=
"bookshelf/book_detais.html"
template_name
=
"bookshelf/book_detai
l
s.html"
class
BooksCreateView
(
CreateView
):
...
...
@@ -25,12 +27,21 @@ class BooksCreateView(CreateView):
fields
=
'__all__'
template_name
=
"bookshelf/add-book.html"
def
post
(
self
,
request
,
*
args
,
**
kwargs
):
form
=
BooksForm
(
request
.
POST
)
if
form
.
is_valid
():
new_book
=
form
.
save
()
detail_link
=
"../"
+
new_book
.
get_absolute_url
()
+
"/details"
return
HttpResponseRedirect
(
detail_link
)
else
:
return
render
(
request
,
self
.
template_name
,
{
'form'
:
form
})
class
BooksUpdateView
(
UpdateView
):
model
=
Books
fields
=
'__all__'
template_name
=
"bookshelf/add-book.html"
template_name
=
"bookshelf/edit-book.html"
class
AuthorsView
(
ListView
):
model
=
Author
...
...
@@ -40,3 +51,14 @@ class AuthorsView(ListView):
class
AuthorsDetailView
(
DetailView
):
model
=
Author
template_name
=
"bookshelf/author_details.html"
# def books_view(request):
# if request.method == 'POST':
# form = BooksForm(request.POST)
# if form.is_valid():
# new_subject = form.save()
# return redirect('book_details', pk=new_subject.pk)
# else:
# form = BooksForm()
# return render(request, 'book_details', {'form': form})
\ No newline at end of file
danielramos_reading/db.sqlite3
View file @
f25f109b
No preview for this file type
danielramos_reading/templates/bookshelf/add-book.html
View file @
f25f109b
...
...
@@ -14,9 +14,9 @@
</ul>
{% endif %}
{% endfor %}
<form
action=
"/books"
method=
"post"
>
<form
method=
"post"
>
{% csrf_token %}
{{ form }}
<input
type=
"submit"
value=
"
Submit
"
>
<input
type=
"submit"
value=
"
Add Book
"
>
</form>
{% endblock %}
\ No newline at end of file
danielramos_reading/templates/bookshelf/book_detais.html
→
danielramos_reading/templates/bookshelf/book_detai
l
s.html
View file @
f25f109b
...
...
@@ -12,6 +12,12 @@
<i>
{{ object.blurb }}
</i>
</p>
<br>
<a
href=
"/books/{{ object.get_absolute_url }}/edit"
>
<input
type=
"submit"
value=
"Edit Book"
>
</a>
<br>
<br>
<br>
...
...
danielramos_reading/templates/bookshelf/edit-book.html
0 → 100644
View file @
f25f109b
{% extends 'base.html' %}
{% load static %}
{% block title %}Edit{% 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 }}
<input
type=
"submit"
value=
"Save Changes"
>
</form>
{% endblock %}
\ 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