This commit is contained in:
Waylon Walker 2023-06-06 09:57:21 -05:00
parent 6b1c60a550
commit 839cbd0dc0
No known key found for this signature in database
GPG key ID: 66E2BF2B4190EFE4
17 changed files with 213 additions and 35 deletions

View file

@ -6,8 +6,7 @@ from learn_sql_model.models.fast_model import FastModel
from learn_sql_model.models.pet import Pet
class Hero(FastModel, table=True):
id: Optional[int] = Field(default=None, primary_key=True)
class HeroBase(FastModel, table=False):
name: str
secret_name: str
age: Optional[int] = None
@ -15,3 +14,23 @@ class Hero(FastModel, table=True):
pet_id: Optional[int] = Field(default=None, foreign_key="pet.id")
pet: Optional[Pet] = Relationship(back_populates="hero")
class Hero(HeroBase, table=True):
id: Optional[int] = Field(default=None, primary_key=True)
class HeroCreate(HeroBase):
...
class HeroRead(HeroBase):
id: Optional[int] = Field(default=None, primary_key=True)
class HeroUpdate(HeroBase):
...
class HeroDelete(HeroBase):
id: Optional[int] = Field(default=None, primary_key=True)

View file

@ -1,3 +1,4 @@
from datetime import datetime
from typing import Optional, TYPE_CHECKING
from sqlmodel import Field, Relationship
@ -11,4 +12,5 @@ if TYPE_CHECKING:
class Pet(FastModel, table=True):
id: Optional[int] = Field(default=None, primary_key=True)
name: str = "Jim"
birthday: Optional[datetime] = None
hero: "Hero" = Relationship(back_populates="pet")