I'm using Django Tables2. My goal is to highlight a specific table cell based on the value of another field. I've implemented a solution using render_foo methods (similar to the solution for this post).
I have a Team_Leader Column and I would like it to be highlighted if New_Team_Leader is True (signifying that the Team_Leader has changed). It's working for the most part, except if the Team_Leader is left blank. When the Team_Leader is blank, the cell accepts the formatting from the previous row. Here is my code:
tables.py
import django_tables2 as tables
Class AuditTable(tables.Table):
def render_Team_Leader(self, value, column, record):
if record.New_Team_Leader == True:
column.attrs={'td': {'class': 'yellow'}}
else:
column.attrs={'td': {}}
return value
This image hopefully demonstrates my problem:
Highlight rule fails when cell value is None
Notice that when the Team_Leader has a value, the highlighting rules work well. When the Team_Leader has not been selected, the cell is highlighted based on the previous record's New_Team_Leader True/False value.
How can I set it up so that the True/False New_Team_Leader formatting rules are applied, even if the Team_Leader is blank?