'Translating django tables2 template column header
Hi i'm working with django-tables2 and I have a table where I need to translate the headers of each column.
class ModelTable(tables.Table):
name = tables.columns.Column()
edit = tables.TemplateColumn('<a href='{% url "edit_my_model_instance" record.id %}'>Edit</a>', verbose_name=u'Edit', )
delete = tables.TemplateColumn('<a href='{% url "del_my_model_instance" record.id %}'>Delete</a>', verbose_name=u'Delete', )
class Meta:
model = models.Model
The above code without translations work fine, but when I add the gettext for translate like this :
delete = tables.TemplateColumn('<a href='{% url "del_my_model_instance" record.id %}'>Delete</a>', verbose_name=_(u'Delete'), )
Where I added gettext as _ : verbose_name=_(u'Delete')
I receive the following error
TypeError: 'TemplateColumn' object is not callable
The thing is if I use tables.Column it works fine with translation, so the problem is only when I user TemplateColumn.
If you can guide me through this I'd appreciate it, thanks.
Solution 1:[1]
Your code looks well related to the verbose_name parameter and should work that way.
But I think you wrongly used the single/double quotes in the first argument of the TemplateColumn. You should use:
delete = tables.TemplateColumn(
'<a href="{% url "price-update" record.id %}">{% trans "Delete" %}</a>',
verbose_name=_("Delete"),
)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Marco |
