This is my template code
<tbody>
{% for item in items %}
<tr class="text-black">
<td>{{ item.name }}</td>
<td>{{ item.description }}</td>
<td>
<a
href="{% url 'menu-options-update' item.id %}"
class="btn btn-sm btn-user edit"
>
<!-- <i class="far fa-edit"></i> -->
<i class="fas fa-pencil-alt"></i
></a>
<a
data-toggle="modal"
class="btn btn-sm btn-user delete btn--show-modal"
href="#myModal"
data-confirm="Are you sure to delete this item?"
><i class="fas fa-trash"></i
></a>
</td>
<div class="modal1 hidden">
<button class="btn--close-modal">×</button>
<h2 class="modal__header">Do you want to delete this record?</h2>
<div class="deletModalBtnContainer">
<a
href="{% url 'menu-options-delete' item.id %}"
class="delete-final btn"
>Delete</a
>
<a href="#" class="cencel-modal btn btn-cancels-close-modal"
>Cencel</a
>
</div>
</div>
</tr>
{% endfor %}
</tbody>
And this is my view
item = MenuOptions.objects.get(id=id)
item.delete()
This code is always picking the 1st id in the table data, not the one on which I have clicked. Let’s suppose my table has 5 rows and I want to delete the 4th row but after I click on the delete button it is deleting the 1st row.