I have a model Product:
class Product(models.Model):
name = models.CharField(verbose_name="name", max_length=40)
cost = models.FloatField(verbose_name="price")
def __unicode__(self):
return self.name
I created a view where i can add new products but how can i delete these products?
my idea:
def delete_product(request, pk):
if request.method == "POST":
if form.is_valid():
product = form.delete(commit=False)
product.delete()
return redirect('homeshop.views.product_list', pk=product.pk)
But what next? I added to template (where i can edit product and save it) but it does not work:
{{ delete_product }}
Now in my template:
{% block content %}
<h1>Nowy wydatek</h1>
<form method="POST" class="product-form">{% csrf_token %}
{{ form.as_p }}
<button type="submit" class="save btn btn-default">Save</button>
</form>
{% endblock %}