first commit

This commit is contained in:
huangzhenpc
2025-02-26 18:29:10 +08:00
parent 5d21c9468c
commit a8d1b41381
38 changed files with 2878 additions and 0 deletions

35
old/app/models/domain.py Normal file
View File

@@ -0,0 +1,35 @@
from sqlalchemy import Column, Integer, String, Boolean, DateTime
from sqlalchemy.orm import relationship
from datetime import datetime
from . import Base
class Domain(Base):
"""邮件域名模型"""
__tablename__ = 'domains'
id = Column(Integer, primary_key=True)
name = Column(String(255), unique=True, nullable=False, index=True)
description = Column(String(500), nullable=True)
active = Column(Boolean, default=True)
created_at = Column(DateTime, default=datetime.utcnow)
updated_at = Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)
# 关系
mailboxes = relationship("Mailbox", back_populates="domain", cascade="all, delete-orphan")
def __repr__(self):
return f"<Domain {self.name}>"
def to_dict(self):
"""转换为字典用于API响应"""
return {
"id": self.id,
"name": self.name,
"description": self.description,
"active": self.active,
"created_at": self.created_at.isoformat() if self.created_at else None,
"updated_at": self.updated_at.isoformat() if self.updated_at else None,
"mailbox_count": len(self.mailboxes) if self.mailboxes else 0
}