25 lines
861 B
Python
25 lines
861 B
Python
"""Project model"""
|
|
from sqlalchemy import Column, String, Text, Integer, ForeignKey, Index
|
|
from sqlalchemy.orm import relationship
|
|
from app.models.base import BaseModel
|
|
|
|
|
|
class Project(BaseModel):
|
|
"""Project containing devices and configurations"""
|
|
__tablename__ = "projects"
|
|
__table_args__ = (
|
|
Index("ix_projects_owner_id", "owner_id"),
|
|
)
|
|
|
|
name = Column(String(255), nullable=False)
|
|
description = Column(Text, nullable=True)
|
|
owner_id = Column(Integer, ForeignKey("users.id"), nullable=False)
|
|
|
|
# Relationships
|
|
owner = relationship("User")
|
|
devices = relationship("Device", back_populates="project", cascade="all, delete-orphan")
|
|
configurations = relationship("Configuration", back_populates="project", cascade="all, delete-orphan")
|
|
|
|
def __repr__(self):
|
|
return f"<Project {self.name}>"
|