Skip to content

Commit 7b1c2aa

Browse files
authored
Merge pull request piccolo-orm#77 from piccolo-orm/column_help_text
Column help text
2 parents f2a8f0a + 0a8ab1d commit 7b1c2aa

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

piccolo/columns/base.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ class ColumnMeta:
123123
index: bool = False
124124
index_method: IndexMethod = IndexMethod.btree
125125
required: bool = False
126+
help_text: t.Optional[str] = None
126127

127128
# Used for representing the table in migrations and the playground.
128129
params: t.Dict[str, t.Any] = field(default_factory=dict)
@@ -244,6 +245,13 @@ class Column(Selectable):
244245
the user must provide this value. Example uses are in serialisers for
245246
API endpoints, and form fields.
246247
248+
:param help_text:
249+
This provides some context about what the column is being used for. For
250+
example, for a `Decimal` column called `value`, it could say
251+
'The units are millions of dollars'. The database doesn't use this
252+
value, but tools such as Piccolo Admin use it to show a tooltip in the
253+
GUI.
254+
247255
"""
248256

249257
value_type: t.Type = int
@@ -257,11 +265,12 @@ def __init__(
257265
index: bool = False,
258266
index_method: IndexMethod = IndexMethod.btree,
259267
required: bool = False,
268+
help_text: t.Optional[str] = None,
260269
**kwargs,
261270
) -> None:
262271
# Used for migrations.
263-
# We deliberately omit 'required' as it doesn't effect the actual
264-
# schema.
272+
# We deliberately omit 'required', and 'help_text' as they don't effect
273+
# the actual schema.
265274
kwargs.update(
266275
{
267276
"null": null,
@@ -288,6 +297,7 @@ def __init__(
288297
index_method=index_method,
289298
params=kwargs,
290299
required=required,
300+
help_text=help_text,
291301
)
292302

293303
self.alias: t.Optional[str] = None

tests/columns/test_base.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,13 @@ def test_copy(self):
3939
self.assertNotEqual(
4040
id(column._meta.call_chain), id(new_column._meta.call_chain)
4141
)
42+
43+
44+
class TestHelpText(TestCase):
45+
def test_help_text(self):
46+
"""
47+
Test adding help text to a column.
48+
"""
49+
help_text = "This is some important help text for users."
50+
column = Varchar(help_text=help_text)
51+
self.assertTrue(column._meta.help_text == help_text)

0 commit comments

Comments
 (0)