Custom name for Foreign Key. #358
-
Hello, is it possible to set a name instead of fk numbers? Thank you. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Yes, it's possible. Piccolo doesn't use the https://piccolo-orm.readthedocs.io/en/latest/piccolo/schema/advanced.html#readable Here's an example: # tables.py
from piccolo.table import Table
from piccolo.columns import Varchar
from piccolo.columns.readable import Readable
class Band(Table, tablename="music_band"):
name = Varchar(length=100)
@classmethod
def get_readable(cls):
return Readable(template="%s", columns=[cls.name]) I had a look, and we don't seem to mention it in the Piccolo Admin docs, only the main Piccolo docs, so this needs changing. The reason we use |
Beta Was this translation helpful? Give feedback.
Yes, it's possible.
Piccolo doesn't use the
__str__
method to determine how the row is displayed. Instead it looks for aget_readable
method:https://piccolo-orm.readthedocs.io/en/latest/piccolo/schema/advanced.html#readable
Here's an example:
I had a look, and we don't seem to mention it in the Piccolo Admin docs, only the main Piccolo docs, so this needs changing.
The reason we use
get_…