diff --git a/main/templates/edit_product.html b/main/templates/edit_product.html
new file mode 100644
index 0000000..8bbd5f7
--- /dev/null
+++ b/main/templates/edit_product.html
@@ -0,0 +1,22 @@
+{% extends 'base.html' %}
+
+{% load static %}
+
+{% block content %}
+
+
Edit Product
+
+
+
+{% endblock %}
\ No newline at end of file
diff --git a/main/templates/main.html b/main/templates/main.html
index cb660de..23b5437 100644
--- a/main/templates/main.html
+++ b/main/templates/main.html
@@ -1,6 +1,29 @@
{% extends 'base.html' %}
{% block content %}
+
+
+
+
+
+
+
Shopping List Page
Name:
@@ -25,6 +48,21 @@ Class:
{{product.price}} |
{{product.description}} |
{{product.date_added}} |
+
+
+
+
+ |
+
+
+
+
+
+ |
{% endfor %}
@@ -39,10 +77,4 @@ Sesi terakhir login: {{ last_login }}
-
-
-
-
{% endblock content %}
\ No newline at end of file
diff --git a/main/urls.py b/main/urls.py
index d831b0a..7f0f2c9 100644
--- a/main/urls.py
+++ b/main/urls.py
@@ -1,5 +1,5 @@
from django.urls import path
-from main.views import show_main, create_product, show_xml, show_json, show_xml_by_id, show_json_by_id, register, login_user, logout_user
+from main.views import show_main, create_product, show_xml, show_json, show_xml_by_id, show_json_by_id, register, login_user, logout_user, edit_product, delete_product
app_name = 'main'
@@ -8,6 +8,8 @@
path('login/', login_user, name='login'),
path('logout/', logout_user, name='logout'),
path('create-product', create_product, name='create_product'),
+ path('edit_product//', edit_product, name='edit_product'),
+ path('delete/', delete_product, name='delete_product'),
path('xml/', show_xml, name='show_xml'),
path('json/', show_json, name='show_json'),
path('xml//', show_xml_by_id, name='show_xml_by_id'),
diff --git a/main/views.py b/main/views.py
index 85da0f2..5118f12 100644
--- a/main/views.py
+++ b/main/views.py
@@ -37,6 +37,29 @@ def create_product(request):
context = {'form': form}
return render(request, "create_product.html", context)
+def edit_product(request, id):
+ # Get product berdasarkan ID
+ product = Product.objects.get(pk = id)
+
+ # Set product sebagai instance dari form
+ form = ProductForm(request.POST or None, instance=product)
+
+ if form.is_valid() and request.method == "POST":
+ # Simpan form dan kembali ke halaman awal
+ form.save()
+ return HttpResponseRedirect(reverse('main:show_main'))
+
+ context = {'form': form}
+ return render(request, "edit_product.html", context)
+
+def delete_product(request, id):
+ # Get data berdasarkan ID
+ product = Product.objects.get(pk = id)
+ # Hapus data
+ product.delete()
+ # Kembali ke halaman awal
+ return HttpResponseRedirect(reverse('main:show_main'))
+
def register(request):
form = UserCreationForm()
diff --git a/templates/base.html b/templates/base.html
index f6727a3..3b01ba8 100644
--- a/templates/base.html
+++ b/templates/base.html
@@ -9,6 +9,13 @@
/>
{% block meta %}
{% endblock meta %}
+
+
+
+