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
65114b8c
Commit
65114b8c
authored
Jul 03, 2024
by
impfundev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: search and ordering books table
parent
6a21a877
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
51 additions
and
4 deletions
+51
-4
book.html
books/templates/book.html
+4
-2
views.py
books/views.py
+19
-2
order_form.html
dashboards/templates/order_form.html
+24
-0
search_form.html
dashboards/templates/search_form.html
+4
-0
No files found.
books/templates/book.html
View file @
65114b8c
{% extends "layout.html" %} {% block dashboard %}
<div
style=
"max-width: 80vw"
class=
"w-100 p-4"
>
<div
class=
"d-flex flex-column gap-2 mb-4"
>
{% include "book_create_form.html" %}
<div
class=
"d-flex gap-2 pb-4"
>
{% include "order_form.html" %}
<button
type=
"button"
class=
"btn btn-primary"
...
...
@@ -9,7 +11,7 @@
>
<i
class=
"bi bi-plus-circle"
></i>
Add Book
</button>
{% include "
book_create
_form.html" %}
{% include "
search
_form.html" %}
</div>
{% include "book_table_data.html" %} {% include "book_delete_form.html" %}
</div>
...
...
books/views.py
View file @
65114b8c
from
django.shortcuts
import
get_object_or_404
,
render
from
django.http
import
HttpResponseRedirect
from
datetime
import
datetime
from
django.db.models
import
Q
from
books.models
import
Book
from
books.forms
import
BookForm
def
index
(
request
):
latest_book_list
=
Book
.
objects
.
order_by
(
"created_at"
)[:
10
]
context
=
{
"books"
:
latest_book_list
,
"form"
:
BookForm
()}
context
=
{
"form"
:
BookForm
()}
latest_book_list
=
Book
.
objects
.
order_by
(
"-created_at"
)[:
10
]
context
[
"books"
]
=
latest_book_list
if
request
.
method
==
"POST"
:
form
=
BookForm
(
request
.
POST
)
...
...
@@ -19,6 +21,21 @@ def index(request):
Book
.
objects
.
create
(
title
=
title
,
stock
=
stock
,
description
=
description
)
if
request
.
method
==
"GET"
:
query
=
request
.
GET
.
get
(
"q"
)
order
=
request
.
GET
.
get
(
"o"
)
if
query
is
not
None
:
filtered_book_list
=
Book
.
objects
.
filter
(
Q
(
title__icontains
=
query
)
|
Q
(
description__icontains
=
query
)
)
.
order_by
(
"-created_at"
)[:
10
]
context
[
"books"
]
=
filtered_book_list
if
order
==
"new"
:
context
[
"books"
]
=
Book
.
objects
.
all
()
.
order_by
(
"-updated_at"
)[:
10
]
elif
order
==
"old"
:
context
[
"books"
]
=
Book
.
objects
.
all
()
.
order_by
(
"updated_at"
)[:
10
]
return
render
(
request
,
"book.html"
,
context
)
...
...
dashboards/templates/order_form.html
0 → 100644
View file @
65114b8c
<div
class=
"dropdown"
>
<button
type=
"button"
class=
"btn btn-secondary dropdown-toggle"
data-bs-toggle=
"dropdown"
aria-expanded=
"false"
>
<i
class=
"bi bi-arrow-down-up"
></i>
Order By
</button>
<ul
class=
"dropdown-menu shadow"
>
<li>
<form
action=
""
method=
"get"
class=
"d-flex gap-2"
>
<input
name=
"o"
value=
"new"
hidden
/>
<button
type=
"submit"
class=
"dropdown-item"
href=
"#"
>
Newest
</button>
</form>
</li>
<li>
<form
action=
""
method=
"get"
class=
"d-flex gap-2"
>
<input
name=
"o"
value=
"old"
hidden
/>
<button
type=
"submit"
class=
"dropdown-item"
href=
"#"
>
Oldest
</button>
</form>
</li>
</ul>
</div>
dashboards/templates/search_form.html
0 → 100644
View file @
65114b8c
<form
action=
""
method=
"get"
class=
"d-flex gap-2"
>
<input
class=
"form-control"
name=
"q"
type=
"text"
placeholder=
"Search..."
/>
<button
type=
"submit"
class=
"btn btn-primary"
>
Enter
</button>
</form>
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