Kanban_clone_backend/models.py

38 lines
No EOL
1.3 KiB
Python

from sqlalchemy import Column, ForeignKey, String, Integer, Table
from sqlalchemy.orm import relationship
from database import Base
from typing import Optional, List
project_user = Table(
"project_user",
Base.metadata,
Column("project_id", Integer, ForeignKey("projects.id"), primary_key=True),
Column("user_id", Integer, ForeignKey("users.id"), primary_key=True)
)
class User(Base):
__tablename__ = "users"
id = Column(Integer, primary_key=True, index=True)
name = Column(String, index=True)
email = Column(String, unique=True, index=True)
projects = relationship("Project", secondary=project_user, back_populates="users")
class Project(Base):
__tablename__ = "projects"
id = Column(Integer, primary_key=True, index=True)
name = Column(String, index=True)
description = Column(String)
users = relationship("User", secondary=project_user, back_populates="projects")
tasks = relationship("Task", back_populates="project")
class Task(Base):
__tablename__ = "tasks"
id = Column(Integer, primary_key=True, index=True)
title = Column(String, index=True)
description = Column(String)
status = Column(String, default="pending")
project_id = Column(Integer, ForeignKey("projects.id"))
project = relationship("Project", back_populates="tasks")