[Django]-Django-tables2: Adding a new custom column not found in model

4👍

You have to pass an empty_values=() keyword argument to the column, to quote the docs:

render methods are only called if the value for a cell is determined to be not an empty value. When a value is inColumn.empty_values, a default value is rendered instead (both Column.render and Table.render_FOO are skipped).

In your case, the ‘value’ for your non-existing column is None, so if that value is in empty_values, the default value (- by default is rendered).

So in code, it could look like this:

class TaskTable(tables.Table):
    foo = tables.Column(empty_values=())

    def render_foo(self):
        raise Exception()

    class Meta:
        model = Task

relevant docs

👤Jieter

Leave a comment