
- Create Category and Tag models - Create TodoTag association table - Add category_id to Todo model - Create Alembic migration for new tables - Create schemas for Category and Tag - Update Todo schemas to include Category and Tags - Create CRUD operations for Categories and Tags - Update Todo CRUD operations to handle categories and tags - Create API endpoints for categories and tags - Update Todo API endpoints with category and tag filtering - Update documentation
29 lines
1008 B
Python
29 lines
1008 B
Python
from enum import Enum as PyEnum
|
|
from sqlalchemy import Boolean, Column, DateTime, Enum, ForeignKey, Integer, String, Text
|
|
from sqlalchemy.orm import relationship
|
|
|
|
from app.db.base import Base
|
|
from app.models.tag import todo_tag
|
|
|
|
|
|
class PriorityLevel(str, PyEnum):
|
|
LOW = "low"
|
|
MEDIUM = "medium"
|
|
HIGH = "high"
|
|
|
|
|
|
class Todo(Base):
|
|
__tablename__ = "todos"
|
|
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
title = Column(String, index=True)
|
|
description = Column(Text, nullable=True)
|
|
is_completed = Column(Boolean, default=False)
|
|
priority = Column(Enum(PriorityLevel), default=PriorityLevel.MEDIUM)
|
|
due_date = Column(DateTime, nullable=True)
|
|
owner_id = Column(Integer, ForeignKey("users.id"))
|
|
category_id = Column(Integer, ForeignKey("categories.id"), nullable=True)
|
|
|
|
owner = relationship("User", back_populates="todos")
|
|
category = relationship("Category", back_populates="todos")
|
|
tags = relationship("Tag", secondary=todo_tag, back_populates="todos") |