Files
TG_autoposter/app/models/group.py
2025-12-18 05:55:32 +09:00

34 lines
1.9 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

from sqlalchemy import Column, Integer, String, Float, DateTime, Boolean
from sqlalchemy.orm import relationship
from datetime import datetime
from .base import Base
class Group(Base):
"""Модель для хранения Telegram групп"""
__tablename__ = 'groups'
id = Column(Integer, primary_key=True)
chat_id = Column(String, unique=True, nullable=False) # ID группы в Telegram
title = Column(String, nullable=False) # Название группы
slow_mode_delay = Column(Integer, default=0) # Задержка между сообщениями (сек)
last_message_time = Column(DateTime, nullable=True) # Время последнего отправленного сообщения
is_active = Column(Boolean, default=True) # Активна ли группа
description = Column(String, nullable=True) # Описание группы (для поиска)
member_count = Column(Integer, default=0) # Количество участников
creator_id = Column(String, nullable=True) # ID создателя группы
created_at = Column(DateTime, default=datetime.utcnow)
updated_at = Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)
# Связь со многими сообщениями (через таблицу связей)
messages = relationship('MessageGroup', back_populates='group', cascade='all, delete-orphan')
# Связь с участниками группы
members = relationship('GroupMember', back_populates='group', cascade='all, delete-orphan')
# Связь с ключевыми словами
keywords = relationship('GroupKeyword', back_populates='group', cascade='all, delete-orphan')
# Связь со статистикой
statistics = relationship('GroupStatistics', back_populates='group', cascade='all, delete-orphan', uselist=False)
def __repr__(self):
return f'<Group {self.chat_id} - {self.title}>'