0

So, I am creating a small app where I need to show an HTML table from the database entries. So I am using Django and the best solution for it was Django_tables2. And for the default setting, where all the fields from the model are being displayed it works ok. But I needed to add another column for a button and that's when I ran into a problem. I cannot add/delete a column or anything in the table. The changes I make in the Table class are rejected and the default settings are being still used.

I tried removing the template or the model from the View class, but nothing worked. I tried editing the Table class again, but nothing. I tried switching the View class from SingleTableView to SingleMixinView, but that just breaks it even more.

This is my Table class:

class InsertTable(tables.Table):
    class Meta:
        model = Insert
        template_name = "list.html"
        fields = ['id', 'name', 'phone', 'description', 'date', 'done', 'edit']
    edit = tables.TemplateColumn(template_name="edit.html", verbose_name="edit", orderable=False)

This is my view class:

class List(SingleTableView):
    model = Insert
    table_class = InsertTable
    template_name = "list.html"
  • The "edit" column is not getting rendered? what does the list.html and edit.html files look like? Also, take a look at this answer, it may help: https://stackoverflow.com/a/55706074/2785080 – Ben Apr 20 '23 at 22:02
  • Yes, the edit column is not getting rendered. Edit.html `Edit` link.html `{% extends 'base.html' %} {% load render_table from django_tables2 %} {% block content %} {% render_table object_list %} {% endblock%}` – Andrej Mickov Apr 24 '23 at 21:57
  • Try using: `{% render_table table %}` instead of `object_list`. `object_list` is the queryset, where `table` is the custom table with the custom `edit` field. – Ben Apr 24 '23 at 22:45
  • I tried, but I get AttributeError with context value. – Andrej Mickov Apr 25 '23 at 11:41

0 Answers0