evaluate sqlmodel
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
import uuid
|
||||
from datetime import datetime
|
||||
|
||||
from sqlmodel import Field, Relationship, SQLModel
|
||||
|
||||
from model.base import AbstractEntity
|
||||
|
||||
|
||||
class Publisher(AbstractEntity, table=True):
|
||||
name: str = Field(index=True, unique=True)
|
||||
comics: list["Comic"] = Relationship(back_populates="publisher")
|
||||
|
||||
def __repr__(self):
|
||||
return f'Publisher({self.id} {self.name})'
|
||||
|
||||
def __str__(self):
|
||||
return self.__repr__()
|
||||
|
||||
|
||||
class Comic(AbstractEntity, table=True):
|
||||
title: str = Field(index=True, unique=True)
|
||||
publisher_id: uuid.UUID | None = Field(default=None, foreign_key="publisher.id")
|
||||
publisher: Publisher | None = Relationship(back_populates="comics")
|
||||
current_order: int = Field(default=False)
|
||||
completed: int = Field(nullable=False)
|
||||
#issues: list["Issue"] = Relationship(back_populates="comic")
|
||||
#story_arcs: list["StoryArc"] = Relationship(back_populates="comic")
|
||||
#trade_paperbacks: list["TradePaperback"] = Relationship(back_populates="comic")
|
||||
#volumes: list["Volume"] = Relationship(back_populates="comic")
|
||||
#comic_works: list["ComicWork"] = Relationship(back_populates="comic")
|
||||
|
||||
|
||||
class Artist(AbstractEntity, table=True):
|
||||
name: str = Field(nullable=False)
|
||||
comic_works: list["ComicWork"] = Relationship(back_populates="artist")
|
||||
|
||||
|
||||
class Worktype(AbstractEntity, table=True):
|
||||
name: str = Field(nullable=False, unique=True)
|
||||
|
||||
#comic_works: list["ComicWork"] = Relationship(back_populates="worktype")
|
||||
|
||||
def __repr__(self):
|
||||
return f'Worktype({self.id} {self.version} {self.name} {len(self.comic_works)})'
|
||||
|
||||
def __str__(self):
|
||||
return f'{self.name}({self.id})'
|
||||
|
||||
|
||||
class ComicWork(AbstractEntity, table=True):
|
||||
__tablename__ = "comic_work"
|
||||
|
||||
comic_id: uuid.UUID | None = Field(nullable=False, foreign_key="comic.id")
|
||||
#comic: Comic = Relationship(back_populates="comic_works")
|
||||
artist_id: uuid.UUID | None = Field(nullable=False, foreign_key="artist.id")
|
||||
artist: Artist = Relationship(back_populates="comic_works")
|
||||
work_type_id: uuid.UUID | None = Field(nullable=False, foreign_key="worktype.id")
|
||||
#worktype = Relationship(back_populates="comic_works")
|
||||
Reference in New Issue
Block a user