evaluate sqlmodel
This commit is contained in:
@@ -0,0 +1 @@
|
||||
from .comic import Comic, Publisher, ComicWork, Artist, Worktype
|
||||
@@ -0,0 +1,11 @@
|
||||
import uuid
|
||||
from datetime import datetime
|
||||
|
||||
from sqlmodel import SQLModel, Field
|
||||
|
||||
|
||||
class AbstractEntity(SQLModel, table=False):
|
||||
id: uuid.UUID = Field(default_factory=uuid.uuid4, primary_key=True)
|
||||
created_date: datetime = Field(default_factory=datetime.now, nullable=False)
|
||||
last_modified_date: datetime = Field(default_factory=datetime.now, nullable=False)
|
||||
version: int = Field(default=0)
|
||||
@@ -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")
|
||||
@@ -0,0 +1,28 @@
|
||||
from sqlmodel import Field, Relationship, table
|
||||
from uuid import UUID
|
||||
from .base import AbstractEntity
|
||||
|
||||
|
||||
|
||||
class MediaActorFile(AbstractEntity, table=True):
|
||||
__tablename__ = "media_actor_file"
|
||||
|
||||
media_actor_id: UUID = Field(nullable=False, foreign_key="media_actor.id")
|
||||
media_file_id: UUID = Field(nullable=False, foreign_key="media_file.id")
|
||||
|
||||
|
||||
class MediaFile(AbstractEntity, table=True):
|
||||
__tablename__ = "media_file"
|
||||
cloud_link: str = Field(nullable=True, max_length=255)
|
||||
file_name: str = Field(nullable=True, max_length=255)
|
||||
path : str = Field(nullable=True, max_length=255)
|
||||
title: str = Field(nullable=True, max_length=255)
|
||||
url: str = Field(nullable=True, max_length=255)
|
||||
actors : list["MediaActor"] = Relationship(back_populates="videos", link_model=MediaActorFile)
|
||||
|
||||
|
||||
class MediaActor(AbstractEntity, table=True):
|
||||
__tablename__ = "media_actor"
|
||||
name: str = Field(nullable=True, max_length=255)
|
||||
videos : list["MediaFile"] = Relationship(back_populates="actors", link_model=MediaActorFile)
|
||||
|
||||
Reference in New Issue
Block a user