( ), .
-, django_tables2.rows.BoundRows:
class ColoredBoundRows(BoundRows):
def __iter__(self):
for record in self.data:
row = BoundRow(record, table=self.table)
row.style = 'some_class'
yield row
def __getitem__(self, key):
container = ColoredBoundRows if isinstance(key, slice) else BoundRow
return container(self.data[key], table=self.table)
:
class YourTable(Table):
def __init__(self, *args, **kwargs):
super(YourTable, self).__init__(*args, **kwargs)
self.rows = ColoredBoundRows(data=self.data, table=self)
( , ):
{% extends "django_tables2/table.html" %}
{% block table.tbody.row %}
<tr class="{% cycle "odd" "even" %} {{ row.style }}">
{% for column, cell in row.items %}
<td {{ column.attrs.td.as_html }}>{{ cell }}</td>
{% endfor %}
</tr>
{% endblock table.tbody.row %}