Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

django-tables2 - accessing values of other columns in a table class

Let's assume I have the following table class:

class TestTable(tables.Table):
    id = tables.Column()
    description = tables.Column()

    def render_description(self, value):
        return mark_safe('''<a href=%s>%s</a>''' % (???, value))

Is it possible to access the value of the column "id" in the render method, so that I can build up a link which leads to the id but shows the text which depends on the 'description'-field?

Thanks in advance!

like image 648
noplacetoh1de Avatar asked Sep 06 '25 09:09

noplacetoh1de


1 Answers

From a quick glance at the docs for render_FOO it looks like you can just do:

class TestTable(tables.Table):
    id = tables.Column()
    description = tables.Column()

    def render_description(self, value, record):
        return mark_safe('''<a href=%s>%s</a>''' % (record.id, value)

Not sure of the exact shape of a row record, so it might be record['id'], the link to the docs should help with exploration...

like image 183
Darb Avatar answered Sep 09 '25 03:09

Darb