django-tables2
django-tables2 copied to clipboard
column.attrs and render behaviour question regarding table headers
Following an example in my code where I tried to optimize in terms of DRY:
class CustomColumn(django_tables2.Column):
def render(self, value, column):
column.attrs = {"td": {"align": "right"},} ### <-- visible in the page source later on
# "th": {"style": "text-align:right"}} ### <-- not visible in the page source later on
if value <= 0:
column.attrs.update({"td": {"align": "right", "style": "color: red"}}) ### <-- visible in the page source later on
return "{:0.2f}".format(value)
class SomeTable(django_tables2.Table):
number = CustomColumn(accessor="get_number",
verbose_name="number",
orderable=False,
attrs = {"th": {"style": "text-align:right"}},) ### <-- visible in the page source later on
name = django_tables2.LinkColumn("name", args=[django_tables2.A("pk")])
class Meta:
model = SomeModel
sequence = ("name", "number",)
exclude = ("id",)
attrs = {"class": "table table-hover table-striped table-borderless",}
Is this the expected behaviour? Why can't I set the