>>> import django_tables as tables
>>> class SimpleTable(tables.Table):
- ... id = tables.Column(formatter=lambda x: '#%d' % x)
- ... age = tables.Column(formatter=lambda x: '%d years old' % x)
+ ... id = tables.Column()
+ ... age = tables.Column()
...
- >>> table = SimpleTable([{'age': 31, 'id': 10}, {'age': 34, 'id': 11}])
- >>> row = table.rows[0]
- >>> for cell in row:
- ... print cell
+ ... class Meta:
+ ... attrs = {'class': 'mytable'}
...
- #10
- 31 years old
-
- As you can see, the only the value of the column is available to the formatter.
- This means that **it's impossible create a formatter that incorporates other
- values of the record**, e.g. a column with an ``<a href="...">`` that uses
- :func:`reverse` with the record's ``pk``.
+ >>> table = SimpleTable()
+ >>> table.as_html()
+ '<table class="mytable">...'
- If formatters aren't powerful enough, you'll need to either :ref:`create a
- Column subclass <subclassing-column>`, or to use the
- :ref:`Table.render_FOO method <table.render_foo>`.
+ Inspired by Django's ORM, the ``class Meta:`` allows you to define extra
+ characteristics of a table. See :class:`Table.Meta` for details.
+.. _table.render_foo:
.. _table.render_foo: