Files
test_task_crm/app/models/contact.py
T
Artem Kashaev 5fcb574aca
Test / test (push) Successful in 15s
Refactor code for improved readability and consistency
- Reformatted function signatures in `organization_service.py` and `task_service.py` for better alignment.
- Updated import statements across multiple files for consistency and organization.
- Enhanced test files by improving formatting and ensuring consistent use of async session factories.
- Added type hints and improved type safety in various service and test files.
- Adjusted `pyproject.toml` to include configuration for isort, mypy, and ruff for better code quality checks.
- Cleaned up unused imports and organized existing ones in several test files.
2025-12-01 16:18:03 +05:00

53 lines
1.5 KiB
Python

"""Contact ORM model and schemas."""
from __future__ import annotations
from datetime import datetime
from pydantic import BaseModel, ConfigDict, EmailStr
from sqlalchemy import DateTime, ForeignKey, Integer, String, func
from sqlalchemy.orm import Mapped, mapped_column, relationship
from app.models.base import Base
class Contact(Base):
"""Represents a CRM contact belonging to an organization."""
__tablename__ = "contacts"
id: Mapped[int] = mapped_column(Integer, primary_key=True)
organization_id: Mapped[int] = mapped_column(ForeignKey("organizations.id", ondelete="CASCADE"))
owner_id: Mapped[int] = mapped_column(ForeignKey("users.id", ondelete="RESTRICT"))
name: Mapped[str] = mapped_column(String(255), nullable=False)
email: Mapped[str | None] = mapped_column(String(320), nullable=True)
phone: Mapped[str | None] = mapped_column(String(64), nullable=True)
created_at: Mapped[datetime] = mapped_column(
DateTime(timezone=True),
server_default=func.now(),
nullable=False,
)
organization = relationship("Organization", back_populates="contacts")
owner = relationship("User", back_populates="owned_contacts")
deals = relationship("Deal", back_populates="contact")
class ContactBase(BaseModel):
organization_id: int
owner_id: int
name: str
email: EmailStr | None = None
phone: str | None = None
class ContactCreate(ContactBase):
pass
class ContactRead(ContactBase):
id: int
created_at: datetime
model_config = ConfigDict(from_attributes=True)