ервый импорт проекта
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
"""Ticket model."""
|
||||
|
||||
from sqlalchemy import Column, String, Text, DateTime, ForeignKey, Integer
|
||||
from sqlalchemy.orm import relationship
|
||||
from app.models.base import Base, TimestampMixin
|
||||
|
||||
|
||||
class Ticket(Base, TimestampMixin):
|
||||
"""Ticket model."""
|
||||
|
||||
__tablename__ = "tickets"
|
||||
__table_args__ = {"sqlite_autoincrement": True}
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
subject = Column(String(4000), nullable=False)
|
||||
description = Column(Text)
|
||||
category_id = Column(Integer, ForeignKey("categories.id", ondelete="SET NULL"), nullable=False)
|
||||
priority_id = Column(Integer, ForeignKey("priorities.id", ondelete="SET NULL"), nullable=False)
|
||||
status_id = Column(Integer, ForeignKey("statuses.id", ondelete="SET NULL"), nullable=False)
|
||||
source = Column(String(20), nullable=False) # email, web, phone, sms
|
||||
opened_by = Column(Integer, ForeignKey("users.id", ondelete="SET NULL"), nullable=False)
|
||||
assigned_to_id = Column(Integer, ForeignKey("users.id", ondelete="SET NULL"))
|
||||
company_id = Column(Integer, ForeignKey("companies.id", ondelete="SET NULL"))
|
||||
location_id = Column(Integer, ForeignKey("locations.id", ondelete="SET NULL"))
|
||||
closed_at = Column(DateTime)
|
||||
|
||||
# Relationships
|
||||
user = relationship("User", back_populates="tickets", foreign_keys=[opened_by])
|
||||
assigned_user = relationship("User", back_populates="assigned_tickets", foreign_keys=[assigned_to_id])
|
||||
category = relationship("Category", back_populates="tickets")
|
||||
priority = relationship("Priority")
|
||||
status = relationship("Status")
|
||||
company = relationship("Company", back_populates="tickets")
|
||||
location = relationship("Location", back_populates="tickets")
|
||||
comments = relationship("Comment", back_populates="ticket", cascade="all, delete-orphan")
|
||||
email_messages = relationship("EmailMessage", back_populates="ticket", cascade="all, delete-orphan")
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return f"<Ticket(id={self.id}, subject='{self.subject}')>"
|
||||
Reference in New Issue
Block a user