Skip to content

Custom name for Foreign Key. #358

Answered by dantownsend
nbowisdar asked this question in Q&A
Discussion options

You must be logged in to vote

Yes, it's possible.

Piccolo doesn't use the __str__ method to determine how the row is displayed. Instead it looks for a get_readable method:

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 get_…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@nbowisdar
Comment options

Answer selected by dantownsend
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants