2021-08-24 12:50:16 +00:00
|
|
|
from typing import List, Optional
|
|
|
|
|
|
|
|
from sqlmodel import Field, Relationship, SQLModel
|
|
|
|
|
|
|
|
|
|
|
|
class Team(SQLModel, table=True):
|
|
|
|
id: Optional[int] = Field(default=None, primary_key=True)
|
2021-12-28 10:48:03 +00:00
|
|
|
name: str = Field(index=True)
|
2021-08-24 12:50:16 +00:00
|
|
|
headquarters: str
|
|
|
|
|
|
|
|
heroes: List["Hero"] = Relationship(back_populates="team")
|
|
|
|
|
|
|
|
|
|
|
|
class Hero(SQLModel, table=True):
|
|
|
|
id: Optional[int] = Field(default=None, primary_key=True)
|
2021-12-28 10:48:03 +00:00
|
|
|
name: str = Field(index=True)
|
2021-08-24 12:50:16 +00:00
|
|
|
secret_name: str
|
2021-12-28 10:48:03 +00:00
|
|
|
age: Optional[int] = Field(default=None, index=True)
|
2021-08-24 12:50:16 +00:00
|
|
|
|
|
|
|
team_id: Optional[int] = Field(default=None, foreign_key="team.id")
|
|
|
|
team: Optional[Team] = Relationship(back_populates="heroes")
|