Automated Action 8557c1426e Enhance Todo application with advanced features
- Add due dates and priority level to todos
- Add tags/categories for better organization
- Implement advanced search and filtering
- Create database migrations for model changes
- Add endpoints for managing tags
- Update documentation

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

44 lines
1.5 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 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)
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")