1👍
✅
I would use format_html
.
Furthermore, you’ll need to add record
as a parameter to the render function, which allows you access its other attributes:
class AmazonColumn(tables.Column):
amazon_url = '<a href="https://www.amazon.com/gp/search?ie=UTF8&index=digital-music&keywords={artist}-{title}">Amazon</a>'
def render(self, record):
return format_html(self.amazon_url, artist=record.artist.name, title=record.title)
You might have to set empty_values=()
where you instantiate the AmazonColumn
in your table.
Source:stackexchange.com