Skip to content

Commit 5ee0080

Browse files
committed
Added a __len__ method to the columns container.
1 parent eb13d2a commit 5ee0080

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

django_tables/base.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,10 @@ def __contains__(self, item):
249249
else:
250250
return item in self.all()
251251

252+
def __len__(self):
253+
self._spawn_columns()
254+
return len([1 for c in self._columns.values() if c.visible])
255+
252256
def __getitem__(self, name):
253257
"""Return a column by name."""
254258
self._spawn_columns()

tests/test_basic.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,15 @@ class StateTable2(GeoAreaTable, tables.ModelTable):
5353
assert 'motto' in StateTable2.base_columns
5454

5555

56+
def test_column_count():
57+
class MyTable(TestTable):
58+
visbible = tables.Column(visible=True)
59+
hidden = tables.Column(visible=False)
60+
61+
# The columns container supports the len() builtin
62+
assert len(MyTable([]).columns) == 1
63+
64+
5665
def test_pagination():
5766
class BookTable(TestTable):
5867
name = tables.Column()

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy