I am looking for nice solution to make a simple subclassed NumericColumn for my tables, based on django-tables2. I started with that:
class NumericColumn(Column):
def render(self, value):
return '{:0,.2f}'.format(value)
It works great until I decided to make negative values red:
class NumericColumn(Column):
attrs = {
'td': {
'class': lambda value: 'text-danger' if value < 0 else ''
}
}
def render(self, value):
return '{:0,.2f}'.format(value)
Code periodically fails with TypeError: '<' not supported between instances of 'str' and 'int'
, and it seems that lambda function receives already formatted value
. I don't see a way to get an original value in record
via accessor, and I don't think that it is nice to make a reverse conversion to Decimal for such comparison. Ok, I can test first character for '-', but it is too ugly.
Please help.