[Django]-Django-tables2 checkbox column name

8👍

✅

CheckBoxColumn has it’s own unique rendering for the header and so it will not show the verbose_name unlike all the other columns. You could subclass CheckBoxColumn to change it’s behavior though.

class CheckBoxColumnWithName(tables.CheckBoxColumn):
    @property
    def header(self):
        return self.verbose_name

class SimpleTable(tables.Table):  
    amend = CheckBoxColumnWithName(verbose_name="Amend", accessor="pk")

Alternatively, you could use a TemplateColumn.

class SimpleTable(tables.Table):  
    amend = TemplateColumn('<input type="checkbox" value="{{ record.pk }}" />', verbose_name="Amend")

Leave a comment