I want the URL parameter to automatically concatenate some domain prefixes when I query the returned data #1385
-
First Check
Commit to Help
Example Code'''python
from sqlalchemy.orm import DeclarativeBase
class Base(DeclarativeBase):
pass
class Test(Base):
__tablename__ = 'test'
id: Mapped[int] = mapped_column(Integer, primary_key=True)
url: Mapped[str] = mapped_column(VARCHAR(255))
# similar
def format_url(self):
return f"http://xxx{self.url}"
''' DescriptionWhen I use the Test model to query data, I hope that the URL I receive will always automatically trigger the format_url function, achieving automatic stitching effect Operating SystemWindows Operating System Detailswin 10 SQLModel Version0.0.22 Python Version3.13.2 Additional ContextNo response |
Beta Was this translation helpful? Give feedback.
Answered by
20-buck-spin
Jun 10, 2025
Replies: 1 comment
-
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 :)
|
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
weeptao
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 :)