Skip to content
Discussion options

You must be logged in to vote

Okay, here's the answer:

1. Create a custom var using either pc.Model or pc.Base

class Bot(pc.Model, table=True):
    slug: str
    name: str
    personality: str
    sample: str

2. Within your state class, create an instance of the custom var class and be sure to instantiate it

class State(pc.State):

    current_bot: Bot = Bot(
        slug="",
        name="",
        personality="",
        sample="",
    )

3. Create a function to populate the variable on page load

    def get_bot(self):
        with pc.session() as session:
            slug = self.get_query_params().get("sl", "Missing slug.")
            bot: Bot = session.execute(Bot.select.filter(Bot.slug == slug)).first()
        …

Replies: 2 comments 1 reply

Comment options

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

Comment options

You must be logged in to vote
0 replies
Answer selected by simonmesmith
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