class User(DB.Model, UserMixin): id = DB.Column(DB.Integer, primary_key=True) email = DB.Column(DB.String(255), unique=True) password = DB.Column(DB.String(255)) active = DB.Column(DB.Boolean()) confirmed_at = DB.Column(DB.DateTime()) roles = DB.relationship('Role', secondary=roles_users, backref=DB.backref('users', lazy='dynamic'))
class User(DB.Model, UserMixin): id = DB.Column(DB.Integer, primary_key=True) name = DB.Column(DB.String(100)) username = DB.Column(DB.String(30)) image = DB.Column(DB.String(100)) password = DB.Column(DB.String(50)) join_date = DB.Column(DB.DateTime) tweets = DB.relationship('Tweet', backref='user', lazy='dynamic') following = DB.relationship('User', secondary=followers, primaryjoin=(followers.c.follower_id == id), secondaryjoin=(followers.c.followee_id == id), backref=DB.backref('followers', lazy='dynamic'), lazy='dynamic') followed_by = DB.relationship('User', secondary=followers, primaryjoin=(followers.c.followee_id == id), secondaryjoin=(followers.c.follower_id == id), backref=DB.backref('followees', lazy='dynamic'), lazy='dynamic')
class Group(Base): __tablename__ = 'auth_group' name = DB.Column(DB.String(128), nullable=False, unique=True) initials = DB.Column(DB.String(10), nullable=False, unique=True) parent_id = DB.Column(DB.Integer, DB.ForeignKey('auth_group.id'), nullable=True) children = DB.relationship('Group', lazy="joined", join_depth=2) roles = DB.relationship('Role', secondary=ROLES, backref=DB.backref('groups'))
class Message(DB.Model): __tablename__ = "messages" id = DB.Column(DB.Integer, primary_key=True) dt = DB.Column(DB.DateTime, nullable=False) text = DB.Column(DB.String(500), nullable=False) sender_id = DB.Column(DB.Integer, DB.ForeignKey("users.id"), nullable=False) sender_username = DB.Column(DB.String(32), DB.ForeignKey("users.username"), nullable=False) receiver_id = DB.Column(DB.Integer, DB.ForeignKey("users.id"), nullable=False) receiver_username = DB.Column(DB.String(32), DB.ForeignKey("users.username"), nullable=False) chat_id = DB.Column(DB.Integer, DB.ForeignKey("chats.id"), nullable=False) chat = DB.relationship( "Chat", backref=DB.backref("messages", cascade="all, delete-orphan"), lazy="joined", ) def __init__(self, text, sender_id, sender_username, receiver_id, receiver_username, chat_id): self.dt = datetime.utcnow() self.text = text self.sender_id = sender_id self.sender_username = sender_username self.receiver_id = receiver_id self.receiver_username = receiver_username self.chat_id = chat_id def __repr__(self): return "<Message %r>" % self.message def to_dict(self): return { "id": self.id, "dt": self.dt.strftime('%Y-%m-%d %H:%M:%S'), "text": self.text, "sender_id": self.sender_id, "sender_username": self.sender_username, "receiver_id": self.receiver_id, "receiver_username": self.receiver_username, "chat_id": self.chat_id, }
class User(DB.Model, UserMixin): """Класс для сущности 'Пользователь системы'""" __tablename__ = 'user' id = DB.Column(DB.Integer, primary_key=True) username = DB.Column(DB.String(50), nullable=False, unique=True) password = DB.Column(DB.String(255), nullable=False, server_default='') active = DB.Column('is_active', DB.Boolean(), nullable=False, server_default='0') roles = DB.relationship('Role', secondary='user_roles', backref=DB.backref('users', lazy='dynamic')) def __repr__(self): return "User(id={id}, username={username}, password={password})". \ format(id=self.id, username=self.username, password=self.password)
class Message(DB.Model): __tablename__ = 'messages' id = DB.Column(DB.Integer, primary_key=True) dt = DB.Column(DB.DateTime, nullable=False) text = DB.Column(DB.String(500), nullable=False) sender_id = DB.Column(DB.Integer, DB.ForeignKey('users.id'), nullable=False) sender_username = DB.Column(DB.String(32), DB.ForeignKey('users.username'), nullable=False) receiver_id = DB.Column(DB.Integer, DB.ForeignKey('users.id'), nullable=False) receiver_username = DB.Column(DB.String(32), DB.ForeignKey('users.username'), nullable=False) chat_id = DB.Column(DB.Integer, DB.ForeignKey('chats.id'), nullable=False) chat = DB.relationship('Chat', backref=DB.backref('messages', cascade="all, delete-orphan"), lazy='joined') def __init__(self, text, sender_id, sender_username, receiver_id, receiver_username, chat_id): self.dt = datetime.utcnow() self.text = text self.sender_id = sender_id self.sender_username = sender_username self.receiver_id = receiver_id self.receiver_username = receiver_username self.chat_id = chat_id def __repr__(self): return '<Message %r>' % self.message def to_dict(self): return { 'id': self.id, 'dt': self.dt.isoformat(), 'text': self.text, 'sender_id': self.sender_id, 'sender_username': self.sender_username, 'receiver_id': self.receiver_id, 'receiver_username': self.receiver_username, 'chat_id': self.chat_id }