Skip to content

Commit

Permalink
Completed deleting products functionality and resolve #62
Browse files Browse the repository at this point in the history
  • Loading branch information
JoyZadan committed Dec 7, 2022
1 parent f5611aa commit c0c5c4f
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 7 deletions.
2 changes: 1 addition & 1 deletion home/templates/home/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ <h2 class="display-4 brand-font-alt text-shadow text-center pt-2 my-5">
{% for brand in brands %}
{% if brand.is_featured %}
<div class="col mb-4">
<div class="card">
<div class="card h-100">
<img class="card-img-top" src="{{ brand.image.url }}" alt="">
<div class="card-body">
<h3 class="card-title brand-font-alt h6 text-center">{{ brand.friendly_name }}</h3>
Expand Down
Binary file added media/Illiyoon-europe-logo.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added media/illiyoon-ceramide-ato-body-lotion.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added media/tonymoly-cherry-blossom-hand-cream.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions products/templates/products/product_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@
{% else %}
<small class="text-muted float-right"><i class="fas fa-star mr-1"></i>No Rating</small>
{% endif %} -->
{% if request.user.is_superuser %}
<small class="ml-3 float-right h6">
<a href="{% url 'edit_product' product.id %}" class="text-purple">Edit</a> |
<a class="text-success" href="{% url 'delete_product' product.id %}">Delete</a>
</small>
{% endif %}
<div class="price-box">
<p class="mb-0 pt-3 pb-1"><span class="h3 text-left font-weight-bold price-font">£{{ product.price }}</span></p>
{% if product.discount > 0.01 %}
Expand Down
10 changes: 6 additions & 4 deletions products/templates/products/products.html
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,12 @@ <h2 class="display-4 brand-font-alt text-shadow text-center my-5">Products</h2>
</a>
</p>

<!-- <span class="float-right">
{{ product.subcategory.friendly_name }}
<i class="fas fa-tag text-warning"></i>
</span> -->
{% if request.user.is_superuser %}
<small class="float-right h6 mt-3">
<a href="{% url 'edit_product' product.id %}" class="text-purple">Edit</a> |
<a class="text-success" href="{% url 'delete_product' product.id %}">Delete</a>
</small>
{% endif %}
{% endif %}

</div>
Expand Down
2 changes: 2 additions & 0 deletions products/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@
path('<int:product_id>/', views.product_detail, name='product_detail'),
path('add/', views.add_product, name='add_product'),
path('edit/<int:product_id>/', views.edit_product, name='edit_product'),
path('delete/<int:product_id>/', views.delete_product,
name='delete_product'),
]
12 changes: 10 additions & 2 deletions products/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ def add_product(request):
if request.method == 'POST':
form = ProductForm(request.POST, request.FILES)
if form.is_valid():
form.save()
product = form.save()
messages.success(request, 'Successfully added product!')
return redirect(reverse('add_product'))
return redirect(reverse('product_detail', args=[product.id]))
else:
messages.error(request, 'Failed to add product. \
Please ensure the form is valid.')
Expand Down Expand Up @@ -125,3 +125,11 @@ def edit_product(request, product_id):
}

return render(request, template, context)


def delete_product(request, product_id):
""" Delete a product from the store """
product = get_object_or_404(Product, pk=product_id)
product.delete()
messages.success(request, 'Product deleted!')
return redirect(reverse('products'))

0 comments on commit c0c5c4f

Please sign in to comment.