Skip to content

Commit 522448b

Browse files
committed
added help_text option to Table
1 parent 9654470 commit 522448b

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

piccolo/table.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ class TableMeta:
5252
non_default_columns: t.List[Column] = field(default_factory=list)
5353
foreign_key_columns: t.List[ForeignKey] = field(default_factory=list)
5454
tags: t.List[str] = field(default_factory=list)
55+
help_text: t.Optional[str] = None
5556
_db: t.Optional[Engine] = None
5657

5758
# Records reverse foreign key relationships - i.e. when the current table
@@ -124,6 +125,7 @@ def __init_subclass__(
124125
tablename: t.Optional[str] = None,
125126
db: t.Optional[Engine] = None,
126127
tags: t.List[str] = [],
128+
help_text: t.Optional[str] = None,
127129
):
128130
"""
129131
Automatically populate the _meta, which includes the tablename, and
@@ -138,6 +140,10 @@ def __init_subclass__(
138140
imported from piccolo_conf.py using ``engine_finder``.
139141
:param tags:
140142
Used for filtering, for example by ``table_finder``.
143+
:param help_text:
144+
A user friendly description of what the table is used for. It isn't
145+
used in the database, but will be used by tools such a Piccolo
146+
Admin for tooltips.
141147
142148
"""
143149
tablename = tablename if tablename else _camel_to_snake(cls.__name__)
@@ -189,6 +195,7 @@ def __init_subclass__(
189195
non_default_columns=non_default_columns,
190196
foreign_key_columns=foreign_key_columns,
191197
tags=tags,
198+
help_text=help_text,
192199
_db=db,
193200
)
194201

tests/table/test_metaclass.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,14 @@ class User(Table):
2323

2424
class MyUser(Table, tablename="user"):
2525
pass
26+
27+
def test_help_text(self):
28+
"""
29+
Make sure help_text can be set for the Table.
30+
"""
31+
help_text = "The manager of a band."
32+
33+
class Manager(Table, help_text=help_text):
34+
pass
35+
36+
self.assertEqual(Manager._meta.help_text, help_text)

0 commit comments

Comments
 (0)