24 lines
1001 B
Python
24 lines
1001 B
Python
from sqlalchemy import Column, Integer, String, Text, Boolean, DateTime, ForeignKey
|
|
from sqlalchemy.orm import relationship
|
|
from app.database import Base
|
|
from app.utils.datetime import utcnow
|
|
|
|
|
|
class Task(Base):
|
|
"""任务模型"""
|
|
__tablename__ = "tasks"
|
|
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
title = Column(String(200), nullable=False)
|
|
description = Column(Text, nullable=True)
|
|
priority = Column(String(20), default="q4") # q1(重要紧急), q2(重要不紧急), q3(不重要紧急), q4(不重要不紧急)
|
|
due_date = Column(DateTime, nullable=True)
|
|
is_completed = Column(Boolean, default=False)
|
|
category_id = Column(Integer, ForeignKey("categories.id"), nullable=True)
|
|
created_at = Column(DateTime, default=utcnow)
|
|
updated_at = Column(DateTime, default=utcnow, onupdate=utcnow)
|
|
|
|
# 关联关系
|
|
category = relationship("Category", back_populates="tasks")
|
|
tags = relationship("Tag", secondary="task_tags", back_populates="tasks")
|