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