Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class AccountEventAssociation(Base):
- __tablename__ = 'account_event_association'
- account_id: Mapped[int] = mapped_column(
- sa.ForeignKey('accounts.id'),
- primary_key=True
- )
- event_id: Mapped[int] = mapped_column(
- sa.ForeignKey('events.id'),
- primary_key=True
- )
- account: Mapped["Account"] = relationship(
- 'Account',
- back_populates='event_associations',
- foreign_keys=[account_id]
- )
- event: Mapped["Event"] = relationship(
- 'Event',
- back_populates='account_associations',
- foreign_keys=[event_id]
- )
- class Account(Base):
- __tablename__ = 'accounts'
- # There is also constraint, that checks 1 <= rating <= 5
- id = sa.Column(sa.Integer, primary_key=True, index=True)
- username = sa.Column(sa.String, unique=True, nullable=False)
- photo = sa.Column(sa.String, unique=True, nullable=True)
- user_id = sa.Column(sa.Integer, sa.ForeignKey('users.id'))
- events: Mapped[List["Event"]] = relationship(
- back_populates='accounts',
- secondary='account_event_association',
- overlaps='account,event'
- )
- event_associations: Mapped[List["AccountEventAssociation"]] = relationship(
- back_populates='account',
- overlaps='events'
- )
- user = relationship('User', back_populates='account')
- event = relationship('Event', back_populates='owner')
- class Event(Base):
- """
- is_active: shows that event was deleted :: false is deleted
- is_done: shows that event ended successfully :: true is end
- """
- __tablename__ = 'events'
- id = sa.Column(sa.Integer, primary_key=True, index=True)
- title = sa.Column(sa.String, nullable=False)
- description = sa.Column(sa.Text, nullable=True)
- address = sa.Column(sa.String, nullable=False)
- start_time = sa.Column(sa.DateTime, nullable=False)
- end_time = sa.Column(sa.DateTime, nullable=True)
- is_closed = sa.Column(sa.Boolean, default=False, nullable=False)
- number_of_members = sa.Column(
- sa.Integer,
- nullable=False
- )
- min_age = sa.Column(
- sa.Integer,
- nullable=False
- )
- max_age = sa.Column(
- sa.Integer,
- nullable=False
- )
- type = sa.Column(
- sa.Enum(
- 'online',
- 'offline', name='type_enum'
- ),
- nullable=False
- )
- created_at = sa.Column(sa.DateTime, default=datetime.now, nullable=False)
- updated_at = sa.Column(sa.DateTime, onupdate=datetime.now)
- is_active = sa.Column(sa.Boolean, default=True, nullable=False)
- is_done = sa.Column(sa.Boolean, default=False, nullable=False)
- owner_id = sa.Column(
- sa.Integer,
- sa.ForeignKey('accounts.id'),
- nullable=True
- )
- owner = relationship('Account', back_populates='event')
- accounts: Mapped[List["Account"]] = relationship(
- back_populates='events',
- secondary='account_event_association',
- overlaps='account,event_associations,event'
- )
- account_associations: Mapped[List["AccountEventAssociation"]] = relationship(
- back_populates='event',
- overlaps='accounts,events'
- )
- notes = sa.Column(sa.Text, nullable=True)
Advertisement
Add Comment
Please, Sign In to add comment