From 4d7381b8302c1c5f42c89fa4d1606d9621c2d6d3 Mon Sep 17 00:00:00 2001 From: Arnab Kumar Shil Date: Fri, 5 May 2023 13:47:52 +0200 Subject: [PATCH 1/5] Update custom-data.rst Accessor is an excellent feature of Django Tables2 but it is not highlighted enough due to lack of documentation. I am adding an example how it can be used with `table.Column` class. --- docs/pages/custom-data.rst | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/docs/pages/custom-data.rst b/docs/pages/custom-data.rst index f28e0ff0..e0b1ff83 100644 --- a/docs/pages/custom-data.rst +++ b/docs/pages/custom-data.rst @@ -34,6 +34,18 @@ 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") # or one.two + >>> table = MyTable(data) + >>> list(map(str, t.rows[1])) + ['four'] + + + + .. _table.render_foo: `Table.render_foo` methods From 026538157dee798fc60db3c1e819c415a43f48df Mon Sep 17 00:00:00 2001 From: Arnab Kumar Shil Date: Fri, 5 May 2023 13:58:55 +0200 Subject: [PATCH 2/5] Update custom-data.rst Fixed formatting of the code --- docs/pages/custom-data.rst | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/docs/pages/custom-data.rst b/docs/pages/custom-data.rst index e0b1ff83..580fc97a 100644 --- a/docs/pages/custom-data.rst +++ b/docs/pages/custom-data.rst @@ -34,7 +34,7 @@ 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: +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): @@ -43,9 +43,6 @@ Moreover, you can use `accessor` with the table columns to access nested values. >>> list(map(str, t.rows[1])) ['four'] - - - .. _table.render_foo: `Table.render_foo` methods From dcdcced2372fd003a7393933c35f5ea2a241f9bc Mon Sep 17 00:00:00 2001 From: Arnab Kumar Shil Date: Fri, 5 May 2023 14:01:32 +0200 Subject: [PATCH 3/5] Update custom-data.rst Updated the example code --- docs/pages/custom-data.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/pages/custom-data.rst b/docs/pages/custom-data.rst index 580fc97a..a2773cba 100644 --- a/docs/pages/custom-data.rst +++ b/docs/pages/custom-data.rst @@ -38,7 +38,7 @@ Moreover, you can use `accessor` with the table columns to access nested values. >>> data = [{"abc": {"one": {"two": "three"}}}, {"abc": {"one": {"two": "four"}}}] >>> class MyTable(tables.Table): - ... abc = tables.Column(accessor="abc__one__two") # or one.two + ... abc = tables.Column(accessor="abc__one__two") # or abc.one.two >>> table = MyTable(data) >>> list(map(str, t.rows[1])) ['four'] From a91df299c73f1ba638bb16ac3afcfcef16c276ba Mon Sep 17 00:00:00 2001 From: Arnab Kumar Shil Date: Mon, 8 May 2023 03:57:57 +0200 Subject: [PATCH 4/5] Update custom-data.rst fixed variable name in documentation --- docs/pages/custom-data.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/pages/custom-data.rst b/docs/pages/custom-data.rst index a2773cba..a7012a5e 100644 --- a/docs/pages/custom-data.rst +++ b/docs/pages/custom-data.rst @@ -40,7 +40,7 @@ Moreover, you can use `accessor` with the table columns to access nested values. >>> class MyTable(tables.Table): ... abc = tables.Column(accessor="abc__one__two") # or abc.one.two >>> table = MyTable(data) - >>> list(map(str, t.rows[1])) + >>> list(map(str, table.rows[1])) ['four'] .. _table.render_foo: From 6a4db89fe4dc40a128c8c3610c918c9ca6d8bffa Mon Sep 17 00:00:00 2001 From: Arnab Kumar Shil Date: Wed, 18 Oct 2023 07:27:25 +0200 Subject: [PATCH 5/5] Update docs/pages/custom-data.rst updated documentation based on feedback Co-authored-by: Jan Pieter Waagmeester --- docs/pages/custom-data.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/pages/custom-data.rst b/docs/pages/custom-data.rst index a7012a5e..adf36c07 100644 --- a/docs/pages/custom-data.rst +++ b/docs/pages/custom-data.rst @@ -38,7 +38,7 @@ Moreover, you can use `accessor` with the table columns to access nested values. >>> data = [{"abc": {"one": {"two": "three"}}}, {"abc": {"one": {"two": "four"}}}] >>> class MyTable(tables.Table): - ... abc = tables.Column(accessor="abc__one__two") # or abc.one.two + ... abc = tables.Column(accessor="abc__one__two") >>> table = MyTable(data) >>> list(map(str, table.rows[1])) ['four']