Skip to content

I want the URL parameter to automatically concatenate some domain prefixes when I query the returned data #1385

Answered by 20-buck-spin
weeptao asked this question in Questions
Discussion options

You must be logged in to vote

This is the pattern I use in my project, works like a charm. If I remember correctly the computed field needs to be outside of a table=True class else bad things happen :)

class TestBase(SQLModel):
    path: str

class Test(TestBase, table=True):
    id: int | None = Field(primary_key=True. default=None)

class TestPublic(TestBase):

    id: int

    @computed_field
    @property
    def url(self) -> str:
        return f"http://xxx{self.path}"

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by weeptao
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
2 participants