Django_tables2 With Edit And Delete Buttons. How To Do It Properly?
I'm building an app that lists, sorts, updates and deletes objects. How can I properly add edit and/or delete buttons to django-tables2 table render? Python version: 3.7 and Django
Solution 1:
I think you can use LinkColumn to add a delete button. You can do it like this:
from django_tables2.utils import A # alias for AccessorclassCashierTable(tables.Table):
delete = = tables.LinkColumn('main:delete_item', args=[A('pk')], attrs={
'a': {'class': 'btn'}
})
Solution 2:
I know i'm answering this very late (after 2 years), but it may help someone, like it helped me. The issue here was with the forloop and the wrong argument fetched in the template.
<ahref="{% url 'main:delete_item' record.pk %}"type="submit"class="btn"><button>{{ item.id }}</button></a>
the argument that should be fetched is "record" to access the actual object being rendered in that row.
Post a Comment for "Django_tables2 With Edit And Delete Buttons. How To Do It Properly?"