Hello, I have a template that shows me the items I want to donate and a final step where I confirm or delete any of these items
views.py
def confirm_donation(request, id):
donation = get_donation(id, request.user)
if not donation:
return redirect('/doacao')
if request.method == 'POST':
donation.confirmed = True
donation.save()
return redirect('/doacao/minhas-doacoes')
items = donation.donationitem_set.all()
return render(request, 'confirm-data.html', {'donation': donation, 'items': items})
def delete_item(request, id):
donation = get_donation(id, request.user)
donation_items = DonationItem.objects\
.filter(donation__donor_id=request.user.id)\
.filter(donation__confirmed=False)
items = donation.donationitem_set.all()
removed_item = donation.donationitem_set.filter(id=id)
removed_item.delete()
print(donation_items.item)
for i in donation_items:
print(i.id)
content={
'donation': donation,
'items': items,
}
return render(request, 'confirm-data.html', content)
and my template confirm-data.html:
<form class="confirm-form" method="POST">
{% csrf_token %}
<div class="register-steps">
<div>
<div class="line"></div>
<div class="step-circle"></div>
<div class="step-circle"></div>
<div class="step-circle step-in"></div>
</div>
<div>
<span style="color: #cccccc">adicionar doação</span>
<span style="color: #cccccc">selecionar escola</span>
<span>confirmar doação</span>
</div>
</div>
<div class="confirm-data">
<h3>Resumo</h3>
<div class="modal">
<div class="confirm-school-name">
<div>
<img src="{% static 'images/user-icon.svg' %}" alt="">
<span>{{donation.school.name}}</span>
</div>
<span>00 mes</span>
</div>
<div class="confirm-list-itens">
{% for item in items %}
<div class="item">
<div>
<span>{{item.quantity}}</span>
<span>{{item.material.name}}</span>
</div>
<div>
<a href="{% url 'donation:delete_item' item.id %}">
<img src="{% static 'images/close-icon.png' %}" alt="">
</a>
</div>
</div>
{% endfor %}
</div>
<div class="confirm-delivery">
{% if donation.delivery == 'DONOR' %}
<span>Levar pessoalmente</span>
{% elif donation.delivery == 'SCHOOL' %}
<span>Quero que retirem</span>
{% endif %}
</div>
</div>
</div>
<div class="btn-submit">
<button class="next arrow-l">
<span>Voltar</span>
<img src="{% static 'images/seta-e.svg'%}" alt="">
</button>
<button class="next arrow-r" type="submit">
<span>Finalizar</span>
<img src="{% static 'images/seta-d.svg'%}" alt="">
</button>
</div>
</form>
The problem that when I click the delete button the id that I get in the url is the one of the item I want to exclude however the item is not deleted and without speaking that as a return the id of the item and not of the donation to the user it seems that deleted all donation, but no.
Can you help me?