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
cb812483
Commit
cb812483
authored
Jul 15, 2024
by
Ilham Maulana
💻
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: book categories overview
parent
7a951276
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
133 additions
and
8 deletions
+133
-8
forms.py
book/forms.py
+16
-1
categories.html
book/templates/categories.html
+12
-0
categories_table_data.html
book/templates/categories_table_data.html
+43
-0
urls.py
book/urls.py
+12
-0
views.py
book/views.py
+48
-5
layout.html
dashboard/templates/layout.html
+2
-2
No files found.
book/forms.py
View file @
cb812483
from
django
import
forms
from
django
import
forms
from
.models
import
Book
from
.models
import
Book
,
Category
class
BookForm
(
forms
.
ModelForm
):
class
BookForm
(
forms
.
ModelForm
):
...
@@ -57,3 +57,18 @@ class BookForm(forms.ModelForm):
...
@@ -57,3 +57,18 @@ class BookForm(forms.ModelForm):
}
}
),
),
}
}
class
CategoryForm
(
forms
.
ModelForm
):
class
Meta
:
model
=
Category
fields
=
[
"name"
]
widgets
=
{
"name"
:
forms
.
TextInput
(
attrs
=
{
"placeholder"
:
"Title"
,
"class"
:
"form-control"
,
}
),
}
book/templates/categories.html
0 → 100644
View file @
cb812483
{% extends "layout.html" %} {% block dashboard %}
<div
style=
"max-width: 80vw"
class=
"w-100 p-4"
>
<div
class=
"d-flex gap-2 pb-4"
>
{% include "order_form.html" %}
<a
type=
"button"
class=
"btn btn-primary"
href=
"/books/categories/add"
>
<i
class=
"bi bi-plus-circle"
></i>
Add Category
</a>
{% include "search_form.html" %}
</div>
{% include "categories_table_data.html" %}
</div>
{% endblock dashboard %}
book/templates/categories_table_data.html
0 → 100644
View file @
cb812483
<table
class=
"table table-hover"
>
<thead>
<tr
class=
"table-primary"
>
<th
scope=
"col"
>
Name
</th>
<th
scope=
"col"
>
Created At
</th>
<th
scope=
"col"
>
Updated At
</th>
<th
scope=
"col"
></th>
</tr>
</thead>
<tbody>
{% if object_list %} {% for category in object_list %}
<tr>
<td>
{{ category.name }}
</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 }}/"
>
<i
class=
"bi bi-pencil-square"
></i>
</a>
<a
class=
"btn btn-danger"
href=
"/books/categories/{{ category.id }}/delete/"
>
<i
class=
"bi bi-trash3-fill"
></i>
</a>
</td>
</tr>
{% endfor %} {% else %}
<tr
class=
"w-100"
>
<td></td>
<td></td>
<td>
<p>
Data Empty
</p>
</td>
<td></td>
</tr>
{% endif %}
</tbody>
</table>
{% include "pagination.html" %}
book/urls.py
View file @
cb812483
...
@@ -5,6 +5,10 @@ from .views import (
...
@@ -5,6 +5,10 @@ from .views import (
BookCreateView
,
BookCreateView
,
BookUpdateView
,
BookUpdateView
,
BookDeleteView
,
BookDeleteView
,
CategoryListView
,
CategoryCreateView
,
CategoryUpdateView
,
CategoryDeleteView
,
)
)
urlpatterns
=
[
urlpatterns
=
[
...
@@ -13,4 +17,12 @@ urlpatterns = [
...
@@ -13,4 +17,12 @@ urlpatterns = [
path
(
"<int:pk>/"
,
BookDetailView
.
as_view
(),
name
=
"book_detail"
),
path
(
"<int:pk>/"
,
BookDetailView
.
as_view
(),
name
=
"book_detail"
),
path
(
"<int:pk>/update/"
,
BookUpdateView
.
as_view
(),
name
=
"book_update"
),
path
(
"<int:pk>/update/"
,
BookUpdateView
.
as_view
(),
name
=
"book_update"
),
path
(
"<int:pk>/delete/"
,
BookDeleteView
.
as_view
(),
name
=
"book_delete"
),
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>/delete/"
,
CategoryDeleteView
.
as_view
(),
name
=
"category_delete"
,
),
]
]
book/views.py
View file @
cb812483
from
django.db.models
import
Q
from
django.db.models
import
Q
from
django.views
import
generic
from
django.views
import
generic
from
.models
import
Book
from
.forms
import
Book
,
BookForm
,
Category
,
CategoryForm
from
.forms
import
BookForm
class
BookListView
(
generic
.
ListView
):
class
BookListView
(
generic
.
ListView
):
...
@@ -40,18 +39,62 @@ class BookDetailView(generic.DeleteView):
...
@@ -40,18 +39,62 @@ class BookDetailView(generic.DeleteView):
class
BookCreateView
(
generic
.
edit
.
CreateView
):
class
BookCreateView
(
generic
.
edit
.
CreateView
):
model
=
Book
model
=
Book
form_class
=
BookForm
form_class
=
BookForm
success_url
=
"/
dashboard/
books/"
success_url
=
"/books/"
template_name
=
"form/create_form.html"
template_name
=
"form/create_form.html"
class
BookUpdateView
(
generic
.
edit
.
UpdateView
):
class
BookUpdateView
(
generic
.
edit
.
UpdateView
):
model
=
Book
model
=
Book
form_class
=
BookForm
form_class
=
BookForm
success_url
=
"/
dashboard/
books"
success_url
=
"/books"
template_name
=
"form/update_form.html"
template_name
=
"form/update_form.html"
class
BookDeleteView
(
generic
.
edit
.
DeleteView
):
class
BookDeleteView
(
generic
.
edit
.
DeleteView
):
model
=
Book
model
=
Book
success_url
=
"/dashboard/books"
success_url
=
"/books"
template_name
=
"form/delete_form.html"
class
CategoryListView
(
generic
.
ListView
):
model
=
Category
template_name
=
"categories.html"
paginate_by
=
5
def
get_queryset
(
self
):
queryset
=
super
()
.
get_queryset
()
keyword
=
self
.
request
.
GET
.
get
(
"q"
)
order
=
self
.
request
.
GET
.
get
(
"o"
)
if
keyword
:
queryset
=
queryset
.
filter
(
Q
(
name__icontains
=
keyword
)
|
Q
(
description__icontains
=
keyword
)
)
.
order_by
(
"-created_at"
)
if
order
:
if
order
==
"new"
:
queryset
=
queryset
.
order_by
(
"-created_at"
)
elif
order
==
"old"
:
queryset
=
queryset
.
order_by
(
"created_at"
)
return
queryset
.
order_by
(
"-updated_at"
)
class
CategoryCreateView
(
generic
.
edit
.
CreateView
):
model
=
Category
form_class
=
CategoryForm
success_url
=
"/books/categories/"
template_name
=
"form/create_form.html"
class
CategoryUpdateView
(
generic
.
edit
.
UpdateView
):
model
=
Category
form_class
=
CategoryForm
success_url
=
"/books/categories/"
template_name
=
"form/update_form.html"
class
CategoryDeleteView
(
generic
.
edit
.
DeleteView
):
model
=
Category
success_url
=
"/books/categories/"
template_name
=
"form/delete_form.html"
template_name
=
"form/delete_form.html"
dashboard/templates/layout.html
View file @
cb812483
...
@@ -21,8 +21,8 @@
...
@@ -21,8 +21,8 @@
><i
class=
"bi bi-book-half"
></i>
Books
</a
><i
class=
"bi bi-book-half"
></i>
Books
</a
>
>
<a
<a
href=
"/categories"
href=
"/
books/
categories"
class=
"btn {% if request.path == '/categories/' %}btn-primary{% else %}btn-outline-primary border-white text-white{% endif %} text-start w-100"
class=
"btn {% if request.path == '/
books/
categories/' %}btn-primary{% else %}btn-outline-primary border-white text-white{% endif %} text-start w-100"
><i
class=
"bi bi-tags-fill"
></i>
Categories
</a
><i
class=
"bi bi-tags-fill"
></i>
Categories
</a
>
>
<a
<a
...
...
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