Skip to content

Commit

Permalink
add classmethod comparable_fields
Browse files Browse the repository at this point in the history
  • Loading branch information
kraanzu committed Sep 24, 2024
1 parent 0f287f0 commit 907f50c
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions dooit/api/model.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
from typing import Any, List, Literal, TypeVar, Self
from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column
from sqlalchemy.ext.declarative import declared_attr
from sqlalchemy import Integer, Float, String, Date, DateTime, inspect
from .manager import manager


comparable_types = (Integer, Float, String, Date, DateTime)
SortMethodType = Literal["description", "status", "due", "urgency", "effort"]
T = TypeVar("T")

Expand All @@ -27,6 +30,20 @@ class DooitModel(BaseModel, BaseModelMixin):
id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True)
order_index: Mapped[int] = mapped_column(default=-1)

@classmethod
def comparable_fields(cls):
to_ignore = ["id", "order_index"]

comparable_fields = [
column.name
for column in inspect(cls).columns
if isinstance(column.type, comparable_types)
and not column.name.endswith("_id")
and column.name not in to_ignore
]

return comparable_fields

@property
def uuid(self) -> str:
return f"{self.__class__.__name__}_{self.id}"
Expand Down

0 comments on commit 907f50c

Please sign in to comment.