Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add example on how to use Accessor to documentation in custom-data.rst #917

Merged
merged 5 commits into from
Oct 18, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions docs/pages/custom-data.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@ The separators ``__`` represent relationships, and are attempted in this order:

If the resulting value is callable, it is called and the return value is used.

Moreover, you can use `accessor` with the table columns to access nested values. For example::

>>> data = [{"abc": {"one": {"two": "three"}}}, {"abc": {"one": {"two": "four"}}}]
>>> class MyTable(tables.Table):
... abc = tables.Column(accessor="abc__one__two")
>>> table = MyTable(data)
>>> list(map(str, table.rows[1]))
['four']

.. _table.render_foo:

`Table.render_foo` methods
Expand Down