Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class User(UserMixin, db.Model):
- __tablename__ = 'user'
- '''
- One to Many relationship between 2 tables.
- The One relationship is User and the Many relationships is Payment
- '''
- id: Mapped[int] = mapped_column(primary_key=True)e
- username: Mapped[str] = mapped_column(String(80), index=True, unique=True)
- email_token: Mapped[Optional[str]] = mapped_column(String())
- rel_payments: Mapped[List["Payments"]] = relationship(back_populates="rel_user")
- def __repr__(self):
- return '<User {}>'.format(self.email)
- class Payments(UserMixin, db.Model):
- '''
- One to Many relationship between 1 table.
- The One relationship is User and the Many relationship is Payments.
- '''
- id: Mapped[int] = mapped_column(primary_key=True)
- item_name: Mapped[str] = mapped_column(String(80))
- price_of_donation: Mapped[int] = mapped_column(Integer)
- # How do I turn email into the foreign key? todo.
- email: Mapped[str] = mapped_column(String(120))
- # The "Many" relationship/connection between the User table + FK
- fk_user_id: Mapped[Optional[int]]= mapped_column(ForeignKey("user.id"))
- rel_user: Mapped[Optional["User"]] = relationship(back_populates="rel_payments")
- def __repr__(self):
- return '<Payments {}>'.format(self.email)
Advertisement
Add Comment
Please, Sign In to add comment