Методы Django Table.render_foo с Boundcolumn
Я запутался, подскажите пожалуйста, как в методы Table.render_foo поместить значение другого поля Term_Implementation? Из документации следует, что для этого нужно использовать Boundcolumn, но я не смог найти конкретного примера для реализации этого.
class EvensList(IncidentsTable, tables.Table):
class Meta:
model = AkpEvents
sequence = ('Term_Implementation', 'Status')
Term_Implementation = tables.DateColumn(empty_values=(),)
Status = tables.Column(empty_values=(),)
def render_Status(self, value, column, columns):
if value == 'Выполнено':
column.attrs = {'td': {'class': 'table-success'}}
elif value == 'В работе':
column.attrs = {'td': {'class': 'table-warning'}}
elif columns['Term_Implementation'] <= date.today():
column.attrs = {'td': {'class': 'table-danger'}}
else:
column.attrs = {'td': {'class': ''}}
return value
Чтобы решить ее, нужно было просто использовать встроенный параметр функции record
, которая возвращает весь объект.
def render_Status(self, value, record, column):
if value == 'Выполнено':
column.attrs = {'td': {'class': 'table-success text-center align-middle'}}
elif value == 'В работе':
column.attrs = {'td': {'class': 'table-warning text-center align-middle'}}
elif record.Term_Implementation <= date.today():
column.attrs = {'td': {'class': 'table-danger text-center align-middle'}}
else:
column.attrs = {'td': {'class': 'text-center align-middle'}}
return value