Search code examples
django-tables2

Django tables2 custom columns not rendering


I'm trying to add a 'Edit' button to all of the rows in my table, I'm using TemplateColumn for this and it simply does not render the button in my table.

This is what I'm trying:

tables.py

from django_tables2 import tables, TemplateColumn
from .models import Conductores


class ConductoresTable(tables.Table):
    class Meta:
        model = Conductores
        template_name = "django_tables2/bootstrap-responsive.html"
        fields = ("nombres", "apellidos", "telefono", "edad", "ine", 'edit')
        attrs = {"class": "table table-hover table-sm"}
        edit = TemplateColumn(
            '<a class="btn btn btn-info btn-sm" href="{% url "conductor_edit" record.id %}">Editar</a>')

this is how it looks at the moment

as you can see it show a '-' instead of the button.


Solution

  • My problem was that the code was under the Meta instead of the class, this solve my problem!