You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
32 lines
832 B
Python
32 lines
832 B
Python
from typing import Optional
|
|
|
|
from sqlmodel import SQLModel, Field
|
|
|
|
|
|
class SongBase(SQLModel):
|
|
"""
|
|
SongBase is the base model that the others inherit from.
|
|
It has two properties, name and artist, both of which are strings.
|
|
This is a data-only model since it lacks table=True, which means
|
|
that it's only used as a pydantic model
|
|
"""
|
|
name: str
|
|
artist: str
|
|
year: Optional[int] = None
|
|
|
|
|
|
class Song(SongBase, table=True):
|
|
"""
|
|
Song, meanwhile, adds an id property to the base model. It's a table model,
|
|
so it's a pydantic and SQLAlchemy model. It represents a database table.
|
|
"""
|
|
id: int = Field(default=None, primary_key=True)
|
|
|
|
|
|
class SongCreate(SongBase):
|
|
"""
|
|
SongCreate is a data-only, pydantic model
|
|
that will be used to create new song instances.
|
|
"""
|
|
pass
|