Skip to content

Commit 87a1cc8

Browse files
committed
moved Readable docs into Advanced page
1 parent 1b187e6 commit 87a1cc8

File tree

3 files changed

+50
-48
lines changed

3 files changed

+50
-48
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
.. _AdvancedSchema:
2+
3+
Advanced
4+
========
5+
6+
Readable
7+
--------
8+
9+
Sometimes Piccolo needs a succinct representation of a row - for example, when
10+
displaying a link in the Piccolo Admin GUI (see :ref:`Ecosystem`). Rather than
11+
just displaying the row ID, we can specify something more user friendly using
12+
``Readable``.
13+
14+
.. code-block:: python
15+
16+
# tables.py
17+
from piccolo.table import Table
18+
from piccolo.columns import Varchar
19+
from piccolo.columns.readable import Readable
20+
21+
22+
class Band(Table, tablename="music_band"):
23+
name = Varchar(length=100)
24+
25+
@classmethod
26+
def get_readable(cls):
27+
return Readable(template="%s", columns=[cls.name])
28+
29+
30+
Specifying the ``get_readable`` classmethod isn't just beneficial for Piccolo
31+
tooling - you can also use it your own queries.
32+
33+
.. code-block:: python
34+
35+
Band.select(Band.get_readable()).run_sync()
36+
37+
Here is an example of a more complex ``Readable``.
38+
39+
.. code-block:: python
40+
41+
class Band(Table, tablename="music_band"):
42+
name = Varchar(length=100)
43+
44+
@classmethod
45+
def get_readable(cls):
46+
return Readable(template="Band %s - %s", columns=[cls.id, cls.name])
47+
48+
As you can see, the template can include multiple columns, and can contain your
49+
own text.

docs/src/piccolo/schema/defining.rst

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -41,51 +41,3 @@ Connecting to the database
4141

4242
In order to create the table and query the database, you need to provide
4343
Piccolo with your connection details. See :ref:`Engines`.
44-
45-
Advanced
46-
--------
47-
48-
Readable
49-
~~~~~~~~
50-
51-
Sometimes Piccolo needs a succinct representation of a row - for example, when
52-
displaying a link in the Piccolo Admin GUI (see :ref:`Ecosystem`). Rather than
53-
just displaying the row ID, we can specify something more user friendly using
54-
``Readable``.
55-
56-
.. code-block:: python
57-
58-
# tables.py
59-
from piccolo.table import Table
60-
from piccolo.columns import Varchar
61-
from piccolo.columns.readable import Readable
62-
63-
64-
class Band(Table, tablename="music_band"):
65-
name = Varchar(length=100)
66-
67-
@classmethod
68-
def get_readable(cls):
69-
return Readable(template="%s", columns=[cls.name])
70-
71-
72-
Specifying the ``get_readable`` classmethod isn't just beneficial for Piccolo
73-
tooling - you can also use it your own queries.
74-
75-
.. code-block:: python
76-
77-
Band.select(Band.get_readable()).run_sync()
78-
79-
Here is an example of a more complex ``Readable``.
80-
81-
.. code-block:: python
82-
83-
class Band(Table, tablename="music_band"):
84-
name = Varchar(length=100)
85-
86-
@classmethod
87-
def get_readable(cls):
88-
return Readable(template="Band %s - %s", columns=[cls.id, cls.name])
89-
90-
As you can see, the template can include multiple columns, and can contain your
91-
own text.

docs/src/piccolo/schema/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ The schema is how you define your database tables, columns and relationships.
88

99
./defining
1010
./column_types
11+
./advanced

0 commit comments

Comments
 (0)