56 lines
1.4 KiB
Python
56 lines
1.4 KiB
Python
from enum import Enum as PyEnum
|
|
|
|
from sqlalchemy import Boolean, Column, DateTime, Enum, Integer, String, Text
|
|
from sqlalchemy.sql import func
|
|
|
|
from app.db.session import Base
|
|
|
|
|
|
class TaskStatus(str, PyEnum):
|
|
"""Enum for task status."""
|
|
|
|
TODO = "todo"
|
|
IN_PROGRESS = "in_progress"
|
|
DONE = "done"
|
|
|
|
|
|
class TaskPriority(str, PyEnum):
|
|
"""Enum for task priority."""
|
|
|
|
LOW = "low"
|
|
MEDIUM = "medium"
|
|
HIGH = "high"
|
|
|
|
|
|
class Task(Base):
|
|
"""SQLAlchemy model for tasks."""
|
|
|
|
__tablename__ = "tasks"
|
|
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
title = Column(String(255), nullable=False, index=True)
|
|
description = Column(Text, nullable=True)
|
|
status = Column(
|
|
Enum(TaskStatus),
|
|
default=TaskStatus.TODO,
|
|
nullable=False,
|
|
index=True
|
|
)
|
|
priority = Column(
|
|
Enum(TaskPriority),
|
|
default=TaskPriority.MEDIUM,
|
|
nullable=False,
|
|
index=True
|
|
)
|
|
due_date = Column(DateTime, nullable=True)
|
|
completed = Column(Boolean, default=False, nullable=False, index=True)
|
|
created_at = Column(DateTime, default=func.now(), nullable=False)
|
|
updated_at = Column(
|
|
DateTime,
|
|
default=func.now(),
|
|
onupdate=func.now(),
|
|
nullable=False
|
|
)
|
|
|
|
def __repr__(self) -> str:
|
|
return f"Task(id={self.id}, title={self.title}, status={self.status})" |