Re-designed record models

This commit is contained in:
linuskmr 2021-12-25 18:58:56 +01:00
parent a7c3f6dfc9
commit 5c75a71609

View file

@ -1,28 +1,21 @@
from datetime import datetime, timedelta
from datetime import datetime
from typing import Optional
import pydantic
from sqlmodel import SQLModel, Field
class RecordBase(SQLModel):
"""Superclass model that all record classes have in common."""
project: str # = Field(description="Name of the project that should be tracked", example="Uni")
tags: list[str] # = Field(description="List of tags by name", example=["Listening Lectures",
# "Not concentrated"])
class RecordStartCreate(RecordBase):
"""Model used when a user starts a record."""
pass
project: int = Field(foreign_key="project.id")
start: datetime = Field(default=datetime.now())
end: Optional[datetime] = Field(default=None)
tags: list[str]
class RecordCreate(RecordBase):
"""Model used when a user creates a complete record."""
start: datetime
end: datetime
"""Model used when a user creates a record."""
pass
class Record(RecordBase, table=True):
@ -34,16 +27,4 @@ class Record(RecordBase, table=True):
class RecordRead(RecordBase):
"""Model used when a user queries a record."""
id: int
start: datetime # = Field(
# description="Start date of record",
# example=datetime.now() - timedelta(hours=3)
# )
end: Optional[datetime] # = Field(
# default=None,
# description="End date of record",
# example=datetime.now()
# )
project: str # = Field(description="Name of the project that should be tracked", example="Uni")
tags: list[str] # = Field(description="List of tags by name", example=["Listening Lectures",
# "Not be concentrated"])
pass