init commit
This commit is contained in:
24
app/models/message_group.py
Normal file
24
app/models/message_group.py
Normal file
@@ -0,0 +1,24 @@
|
||||
from sqlalchemy import Column, Integer, String, ForeignKey, DateTime, Boolean
|
||||
from sqlalchemy.orm import relationship
|
||||
from datetime import datetime
|
||||
from .base import Base
|
||||
|
||||
|
||||
class MessageGroup(Base):
|
||||
"""Модель для связи между сообщениями и группами"""
|
||||
__tablename__ = 'message_groups'
|
||||
|
||||
id = Column(Integer, primary_key=True)
|
||||
message_id = Column(Integer, ForeignKey('messages.id'), nullable=False)
|
||||
group_id = Column(Integer, ForeignKey('groups.id'), nullable=False)
|
||||
is_sent = Column(Boolean, default=False) # Было ли отправлено в эту группу
|
||||
sent_at = Column(DateTime, nullable=True) # Время отправки
|
||||
error = Column(String, nullable=True) # Ошибка при отправке, если была
|
||||
created_at = Column(DateTime, default=datetime.utcnow)
|
||||
|
||||
# Обратные связи
|
||||
message = relationship('Message', back_populates='groups')
|
||||
group = relationship('Group', back_populates='messages')
|
||||
|
||||
def __repr__(self):
|
||||
return f'<MessageGroup msg_id={self.message_id} group_id={self.group_id}>'
|
||||
Reference in New Issue
Block a user