jabajke

Untitled

May 25th, 2023
23
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.23 KB | None | 0 0
  1.  
  2. class AccountEventAssociation(Base):
  3. __tablename__ = 'account_event_association'
  4.  
  5. account_id: Mapped[int] = mapped_column(
  6. sa.ForeignKey('accounts.id'),
  7. primary_key=True
  8. )
  9. event_id: Mapped[int] = mapped_column(
  10. sa.ForeignKey('events.id'),
  11. primary_key=True
  12. )
  13. account: Mapped["Account"] = relationship(
  14. 'Account',
  15. back_populates='event_associations',
  16. foreign_keys=[account_id]
  17. )
  18. event: Mapped["Event"] = relationship(
  19. 'Event',
  20. back_populates='account_associations',
  21. foreign_keys=[event_id]
  22. )
  23.  
  24.  
  25. class Account(Base):
  26. __tablename__ = 'accounts'
  27.  
  28. # There is also constraint, that checks 1 <= rating <= 5
  29. id = sa.Column(sa.Integer, primary_key=True, index=True)
  30. username = sa.Column(sa.String, unique=True, nullable=False)
  31.  
  32. photo = sa.Column(sa.String, unique=True, nullable=True)
  33. user_id = sa.Column(sa.Integer, sa.ForeignKey('users.id'))
  34. events: Mapped[List["Event"]] = relationship(
  35. back_populates='accounts',
  36. secondary='account_event_association',
  37. overlaps='account,event'
  38. )
  39. event_associations: Mapped[List["AccountEventAssociation"]] = relationship(
  40. back_populates='account',
  41. overlaps='events'
  42. )
  43. user = relationship('User', back_populates='account')
  44. event = relationship('Event', back_populates='owner')
  45.  
  46.  
  47.  
  48. class Event(Base):
  49. """
  50. is_active: shows that event was deleted :: false is deleted
  51. is_done: shows that event ended successfully :: true is end
  52. """
  53. __tablename__ = 'events'
  54.  
  55. id = sa.Column(sa.Integer, primary_key=True, index=True)
  56. title = sa.Column(sa.String, nullable=False)
  57. description = sa.Column(sa.Text, nullable=True)
  58. address = sa.Column(sa.String, nullable=False)
  59. start_time = sa.Column(sa.DateTime, nullable=False)
  60. end_time = sa.Column(sa.DateTime, nullable=True)
  61. is_closed = sa.Column(sa.Boolean, default=False, nullable=False)
  62. number_of_members = sa.Column(
  63. sa.Integer,
  64. nullable=False
  65. )
  66. min_age = sa.Column(
  67. sa.Integer,
  68. nullable=False
  69. )
  70. max_age = sa.Column(
  71. sa.Integer,
  72. nullable=False
  73. )
  74. type = sa.Column(
  75. sa.Enum(
  76. 'online',
  77. 'offline', name='type_enum'
  78. ),
  79. nullable=False
  80. )
  81. created_at = sa.Column(sa.DateTime, default=datetime.now, nullable=False)
  82. updated_at = sa.Column(sa.DateTime, onupdate=datetime.now)
  83. is_active = sa.Column(sa.Boolean, default=True, nullable=False)
  84. is_done = sa.Column(sa.Boolean, default=False, nullable=False)
  85. owner_id = sa.Column(
  86. sa.Integer,
  87. sa.ForeignKey('accounts.id'),
  88. nullable=True
  89. )
  90. owner = relationship('Account', back_populates='event')
  91.  
  92. accounts: Mapped[List["Account"]] = relationship(
  93. back_populates='events',
  94. secondary='account_event_association',
  95. overlaps='account,event_associations,event'
  96. )
  97. account_associations: Mapped[List["AccountEventAssociation"]] = relationship(
  98. back_populates='event',
  99. overlaps='accounts,events'
  100. )
  101. notes = sa.Column(sa.Text, nullable=True)
Advertisement
Add Comment
Please, Sign In to add comment