49 lines
1.3 KiB
Python
49 lines
1.3 KiB
Python
"""Organization ORM model and schemas."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from datetime import datetime
|
|
|
|
from pydantic import BaseModel, ConfigDict
|
|
from sqlalchemy import DateTime, Integer, String, func
|
|
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
|
|
|
from app.models.base import Base
|
|
|
|
|
|
class Organization(Base):
|
|
"""Represents a CRM organization/workspace."""
|
|
|
|
__tablename__ = "organizations"
|
|
|
|
id: Mapped[int] = mapped_column(Integer, primary_key=True, index=True)
|
|
name: Mapped[str] = mapped_column(String(255), nullable=False, unique=True)
|
|
created_at: Mapped[datetime] = mapped_column(
|
|
DateTime(timezone=True),
|
|
server_default=func.now(),
|
|
nullable=False,
|
|
)
|
|
|
|
members = relationship(
|
|
"OrganizationMember",
|
|
back_populates="organization",
|
|
cascade="all, delete-orphan",
|
|
)
|
|
contacts = relationship("Contact", back_populates="organization", cascade="all, delete-orphan")
|
|
deals = relationship("Deal", back_populates="organization", cascade="all, delete-orphan")
|
|
|
|
|
|
class OrganizationBase(BaseModel):
|
|
name: str
|
|
|
|
|
|
class OrganizationCreate(OrganizationBase):
|
|
pass
|
|
|
|
|
|
class OrganizationRead(OrganizationBase):
|
|
id: int
|
|
created_at: datetime
|
|
|
|
model_config = ConfigDict(from_attributes=True)
|