Skip to content

Enable inheriting methods from schemas #25

@ch-ahindura

Description

@ch-ahindura

Is your feature request related to a problem? Please describe.
Many times I just want to define my methods on the schema and have them available to all model types.
Could we allow for that?

Example:

class Booking(BaseModel):
    id: str = Field()
    start: datetime = Field()
    end: datetime = Field()

    @computed_field
    @property
    def duration_secs(self) -> float:
        """The duration in seconds"""
        return (self.end - self.start).total_seconds()

SqlBooking = SQLModel("SqlBooking", Booking)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions