Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
L
library-app-django
Project
Project
Details
Activity
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
Ilham Maulana
library-app-django
Commits
59ef92c9
Commit
59ef92c9
authored
Jul 17, 2024
by
Ilham Maulana
💻
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: book list in category detail
parent
40b62c33
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
59 additions
and
5 deletions
+59
-5
book_table_data.html
book/templates/book_table_data.html
+0
-2
categories_table_data.html
book/templates/categories_table_data.html
+2
-2
category_detail.html
book/templates/category_detail.html
+27
-0
urls.py
book/urls.py
+11
-1
views.py
book/views.py
+19
-0
No files found.
book/templates/book_table_data.html
View file @
59ef92c9
...
...
@@ -3,7 +3,6 @@
<tr
class=
"table-primary"
>
<th
scope=
"col"
>
Title
</th>
<th
scope=
"col"
>
Category
</th>
<th
scope=
"col"
>
Description
</th>
<th
scope=
"col"
>
Published Date
</th>
<th
scope=
"col"
>
Created At
</th>
<th
scope=
"col"
>
Updated At
</th>
...
...
@@ -15,7 +14,6 @@
<tr>
<td><a
href=
"/books/{{ book.id }}/"
>
{{ book.title }}
</a></td>
<td>
{{ book.category.name }}
</td>
<td>
{{ book.description }}
</td>
<td>
{{ book.publish_date }}
</td>
<td>
{{ book.created_at }}
</td>
<td>
{{ book.updated_at }}
</td>
...
...
book/templates/categories_table_data.html
View file @
59ef92c9
...
...
@@ -10,13 +10,13 @@
<tbody>
{% if object_list %} {% for category in object_list %}
<tr>
<td>
{{ category.name }}
</td>
<td>
<a
href=
"/books/categories/{{ category.id }}/"
>
{{ category.name }}
</a>
</td>
<td>
{{ category.created_at }}
</td>
<td>
{{ category.updated_at }}
</td>
<td
class=
"d-flex gap-2"
>
<a
class=
"btn btn-success"
href=
"/books/categories/{{ category.id }}/"
href=
"/books/categories/{{ category.id }}/
update/
"
>
<i
class=
"bi bi-pencil-square"
></i>
</a>
...
...
book/templates/category_detail.html
0 → 100644
View file @
59ef92c9
{% extends "layout.html" %} {% block dashboard %}
<div
style=
"max-width: 80vw"
class=
"w-100 p-4"
>
<div
class=
"d-flex justify-content-between pb-4"
>
<div
class=
"d-flex gap-2 pb-4"
>
<a
class=
"btn btn-success"
href=
"/books/categories/{{ category.id }}/update"
>
<i
class=
"bi bi-pencil-square"
></i>
Edit
</a>
<a
class=
"btn btn-danger"
href=
"/books/categories/{{ category.id }}/delete/"
>
<i
class=
"bi bi-trash3-fill"
></i>
Delete
</a>
</div>
</div>
<div
class=
"d-flex gap-5"
>
<div
class=
"col"
>
<h1
class=
"h2 row"
>
{{ category.name }}
</h1>
<time
datetime=
"{{ category.created_at }}"
class=
"row fs-6"
>
Created at: {{ category.created_at }}
</time
>
<time
datetime=
"{{ category.updated_at }}"
class=
"row fs-6"
>
Updated at: {{ category.updated_at }}
</time
>
<h2
class=
"h3 row mt-4"
>
List book with category {{ category.name }}
</h2>
{% include "book_table_data.html" %}
</div>
</div>
{% endblock dashboard %}
\ No newline at end of file
book/urls.py
View file @
59ef92c9
...
...
@@ -6,6 +6,7 @@ from .views import (
BookUpdateView
,
BookDeleteView
,
CategoryListView
,
CategoryDetailView
,
CategoryCreateView
,
CategoryUpdateView
,
CategoryDeleteView
,
...
...
@@ -19,7 +20,16 @@ urlpatterns = [
path
(
"<int:pk>/delete/"
,
BookDeleteView
.
as_view
(),
name
=
"book_delete"
),
path
(
"categories/"
,
CategoryListView
.
as_view
(),
name
=
"category_list"
),
path
(
"categories/add/"
,
CategoryCreateView
.
as_view
(),
name
=
"category_update"
),
path
(
"categories/<int:pk>/"
,
CategoryUpdateView
.
as_view
(),
name
=
"category_update"
),
path
(
"categories/<int:pk>/"
,
CategoryDetailView
.
as_view
(),
name
=
"category_detail"
,
),
path
(
"categories/<int:pk>/update/"
,
CategoryUpdateView
.
as_view
(),
name
=
"category_update"
,
),
path
(
"categories/<int:pk>/delete/"
,
CategoryDeleteView
.
as_view
(),
...
...
book/views.py
View file @
59ef92c9
...
...
@@ -80,6 +80,25 @@ class CategoryListView(generic.ListView):
return
queryset
.
order_by
(
"-updated_at"
)
class
CategoryDetailView
(
generic
.
DetailView
):
model
=
Category
template_name
=
"category_detail.html"
context_object_name
=
"category"
def
get_context_data
(
self
,
**
kwargs
):
"""Insert the single object into the context dict."""
context
=
{}
if
self
.
object
:
context
[
"object"
]
=
self
.
object
context_object_name
=
self
.
get_context_object_name
(
self
.
object
)
books
=
Book
.
objects
.
filter
(
category
=
self
.
object
.
id
)
context
[
"object_list"
]
=
books
if
context_object_name
:
context
[
context_object_name
]
=
self
.
object
context
.
update
(
kwargs
)
return
super
()
.
get_context_data
(
**
context
)
class
CategoryCreateView
(
generic
.
edit
.
CreateView
):
model
=
Category
form_class
=
CategoryForm
...
...
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