Skip to content
Discussion options

You must be logged in to vote

You can get most of the way there with sa_column to decouple the Python attribute name from the DB column name, plus computed_field for the derived accessor:

from sqlalchemy import Column, Integer
from sqlmodel import SQLModel, Field
from pydantic import computed_field


class Foo(SQLModel, table=True):
    field1_: int = Field(sa_column=Column("field1", Integer))
    field2_: int = Field(sa_column=Column("field2", Integer))
    field3_: int = Field(sa_column=Column("field3", Integer))

    @computed_field
    @property
    def fields(self) -> list[int]:
        return [self.field1_, self.field2_, self.field3_]

sa_column=Column("field1", ...) maps the attribute to the real (ugly) column n…

Replies: 1 comment 1 reply

Comment options

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

Answer selected by madduck
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