Automated Action 660c28b96c Add subtasks and reminders functionality
- Added subtask model with CRUD operations
- Added reminder functionality to Todo model
- Added endpoints for managing subtasks and reminders
- Created new migration for subtasks and reminders
- Updated documentation

generated with BackendIM... (backend.im)
2025-05-12 23:37:35 +00:00

63 lines
2.3 KiB
Python

from sqlalchemy import Boolean, Column, Integer, String, Text, DateTime, Enum, Table, ForeignKey
from sqlalchemy.orm import relationship
from sqlalchemy.sql import func
import enum
from .database import Base
# Association table for the many-to-many relationship between Todo and Tag
todo_tag = Table(
"todo_tag",
Base.metadata,
Column("todo_id", Integer, ForeignKey("todos.id"), primary_key=True),
Column("tag_id", Integer, ForeignKey("tags.id"), primary_key=True)
)
class PriorityLevel(str, enum.Enum):
LOW = "low"
MEDIUM = "medium"
HIGH = "high"
class Tag(Base):
__tablename__ = "tags"
id = Column(Integer, primary_key=True, index=True)
name = Column(String(50), nullable=False, unique=True, index=True)
created_at = Column(DateTime(timezone=True), server_default=func.now())
# Relationship to todos
todos = relationship("Todo", secondary=todo_tag, back_populates="tags")
class Subtask(Base):
__tablename__ = "subtasks"
id = Column(Integer, primary_key=True, index=True)
title = Column(String(100), nullable=False)
completed = Column(Boolean, default=False)
created_at = Column(DateTime(timezone=True), server_default=func.now())
updated_at = Column(DateTime(timezone=True), onupdate=func.now())
# Foreign key relationship
todo_id = Column(Integer, ForeignKey("todos.id", ondelete="CASCADE"), nullable=False)
# Relationship to parent todo
todo = relationship("Todo", back_populates="subtasks")
class Todo(Base):
__tablename__ = "todos"
id = Column(Integer, primary_key=True, index=True)
title = Column(String(100), nullable=False)
description = Column(Text, nullable=True)
completed = Column(Boolean, default=False)
priority = Column(Enum(PriorityLevel), default=PriorityLevel.MEDIUM)
due_date = Column(DateTime(timezone=True), nullable=True)
remind_at = Column(DateTime(timezone=True), nullable=True)
created_at = Column(DateTime(timezone=True), server_default=func.now())
updated_at = Column(DateTime(timezone=True), onupdate=func.now())
# Relationship to tags
tags = relationship("Tag", secondary=todo_tag, back_populates="todos")
# Relationship to subtasks
subtasks = relationship("Subtask", back_populates="todo", cascade="all, delete-orphan")