Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
C
crud
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
Dio Maulana
crud
Commits
cee9341c
Commit
cee9341c
authored
Feb 03, 2022
by
dio maulana
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
day 2
parent
dff378e7
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
53 additions
and
4 deletions
+53
-4
index.html
belajar/templates/belajar/index.html
+17
-1
search.html
belajar/templates/belajar/search.html
+18
-1
views.py
belajar/views.py
+18
-2
No files found.
belajar/templates/belajar/index.html
View file @
cee9341c
...
@@ -17,7 +17,7 @@
...
@@ -17,7 +17,7 @@
</thead>
</thead>
<tbody>
<tbody>
{% if latest_product_list %}
{% if latest_product_list %}
{% for product in
latest_product_list
%}
{% for product in
page_obj
%}
<tr>
<tr>
<th
scope=
"row"
>
{{ product.id }}
</th>
<th
scope=
"row"
>
{{ product.id }}
</th>
<td>
{{ product.name_product }}
</td>
<td>
{{ product.name_product }}
</td>
...
@@ -53,7 +53,23 @@
...
@@ -53,7 +53,23 @@
{% endif %}
{% endif %}
</tbody>
</tbody>
</table>
</table>
<div
class=
"pagination"
>
<span
class=
"step-links"
>
{% if page_obj.has_previous %}
<a
href=
"?page=1"
>
«
first
</a>
<a
href=
"?page={{ page_obj.previous_page_number }}"
>
previous
</a>
{% endif %}
<span
class=
"current"
>
Page {{ page_obj.number }} of {{ page_obj.paginator.num_pages }}.
</span>
{% if page_obj.has_next %}
<a
href=
"?page={{ page_obj.next_page_number }}"
>
next
</a>
<a
href=
"?page={{ page_obj.paginator.num_pages }}"
>
last
»
</a>
{% endif %}
</span>
</div>
</div>
</div>
{% endblock %}
{% endblock %}
...
...
belajar/templates/belajar/search.html
View file @
cee9341c
...
@@ -18,7 +18,7 @@
...
@@ -18,7 +18,7 @@
</thead>
</thead>
{% if search %}
{% if search %}
<tbody>
<tbody>
{% for product in
search
%}
{% for product in
page_obj
%}
<tr>
<tr>
<th
scope=
"row"
>
{{ product.id }}
</th>
<th
scope=
"row"
>
{{ product.id }}
</th>
<td>
{{ product.name_product }}
</td>
<td>
{{ product.name_product }}
</td>
...
@@ -54,5 +54,22 @@
...
@@ -54,5 +54,22 @@
</tbody>
</tbody>
{% endif %}
{% endif %}
</table>
</table>
<div
class=
"pagination"
>
<span
class=
"step-links"
>
{% if page_obj.has_previous %}
<a
href=
"?q={{getSearch}}&page=1"
>
«
first
</a>
<a
href=
"?q={{getSearch}}&page={{ page_obj.previous_page_number }}"
>
previous
</a>
{% endif %}
<span
class=
"current"
>
Page {{ page_obj.number }} of {{ page_obj.paginator.num_pages }}.
</span>
{% if page_obj.has_next %}
<a
href=
"?q={{getSearch}}&page={{ page_obj.next_page_number }}"
>
next
</a>
<a
href=
"?q={{getSearch}}&page={{ page_obj.paginator.num_pages }}"
>
last
»
</a>
{% endif %}
</span>
</div>
</div>
</div>
{% endblock %}
{% endblock %}
\ No newline at end of file
belajar/views.py
View file @
cee9341c
...
@@ -6,6 +6,7 @@ from django.http import HttpResponse
...
@@ -6,6 +6,7 @@ from django.http import HttpResponse
from
django.shortcuts
import
get_object_or_404
,
render
from
django.shortcuts
import
get_object_or_404
,
render
from
.models
import
Product
from
.models
import
Product
from
.models
import
Category
from
.models
import
Category
from
django.core.paginator
import
Paginator
def
index
(
request
):
def
index
(
request
):
# latest_product_list = Product.objects.order_by('-id')
# latest_product_list = Product.objects.order_by('-id')
...
@@ -18,9 +19,20 @@ def index(request):
...
@@ -18,9 +19,20 @@ def index(request):
# short hand
# short hand
latest_product_list
=
Product
.
objects
.
order_by
(
'id'
)
latest_product_list
=
Product
.
objects
.
order_by
(
'id'
)
context
=
{
'latest_product_list'
:
latest_product_list
}
paginator
=
Paginator
(
latest_product_list
,
3
)
# Show 25 contacts per page.
page_number
=
request
.
GET
.
get
(
'page'
)
page_obj
=
paginator
.
get_page
(
page_number
)
context
=
{
'latest_product_list'
:
latest_product_list
,
'page_obj'
:
page_obj
}
return
render
(
request
,
'belajar/index.html'
,
context
)
return
render
(
request
,
'belajar/index.html'
,
context
)
# latest_product_list = Product.objects.all()
# paginator = Paginator(latest_product_list, 1) # Show 25 contacts per page.
#
# page_number = request.GET.get('page')
# page_obj = paginator.get_page(page_number)
# return render(request, 'belajar/index.html', {'page_obj': page_obj})
def
edit
(
request
,
product_id
):
def
edit
(
request
,
product_id
):
# product_detail = Product.objects.raw(f'SELECT * FROM belajar_product WHERE id = {product_id}')
# product_detail = Product.objects.raw(f'SELECT * FROM belajar_product WHERE id = {product_id}')
product_detail
=
Product
.
objects
.
get
(
id
=
product_id
)
product_detail
=
Product
.
objects
.
get
(
id
=
product_id
)
...
@@ -76,5 +88,9 @@ def delete(request, product_id):
...
@@ -76,5 +88,9 @@ def delete(request, product_id):
def
search
(
request
):
def
search
(
request
):
getSearch
=
request
.
GET
[
'q'
]
getSearch
=
request
.
GET
[
'q'
]
search
=
Product
.
objects
.
filter
(
name_product__icontains
=
getSearch
)
search
=
Product
.
objects
.
filter
(
name_product__icontains
=
getSearch
)
context
=
{
'search'
:
search
}
paginator
=
Paginator
(
search
,
3
)
# Show 25 contacts per page.
page_number
=
request
.
GET
.
get
(
'page'
)
page_obj
=
paginator
.
get_page
(
page_number
)
context
=
{
'search'
:
search
,
'page_obj'
:
page_obj
,
'getSearch'
:
getSearch
}
return
render
(
request
,
'belajar/search.html'
,
context
)
return
render
(
request
,
'belajar/search.html'
,
context
)
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