jabajke

Untitled

May 15th, 2023
21
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. # auth.models
  2. from datetime import datetime
  3.  
  4. import sqlalchemy as sa
  5. from sqlalchemy.orm import relationship
  6.  
  7. from src.core.database import Base
  8.  
  9.  
  10. class User(Base):
  11. __tablename__ = 'users'
  12.  
  13. id = sa.Column(sa.Integer, primary_key=True, index=True)
  14. email = sa.Column(sa.String, unique=True, index=True)
  15. first_name = sa.Column(sa.String, nullable=False)
  16. last_name = sa.Column(sa.String, nullable=False)
  17. hashed_password = sa.Column(sa.String)
  18. is_active = sa.Column(sa.Boolean, default=False)
  19. birthdate = sa.Column(sa.Date, nullable=False)
  20. created_at = sa.Column(sa.DateTime, default=datetime.now)
  21. updated_at = sa.Column(sa.DateTime, onupdate=datetime.now)
  22. account = relationship('Account', uselist=False, backref='users')
  23.  
  24.  
  25. # account.models
  26. import sqlalchemy as sa
  27. from sqlalchemy.orm import relationship
  28.  
  29. from event.associations import AccountEventAssociation
  30. from event.models import Event
  31. from src.core.database import Base
  32.  
  33.  
  34. class Account(Base):
  35. __tablename__ = 'accounts'
  36.  
  37. # There is also constraint, that checks 1 <= rating <= 5
  38. id = sa.Column(sa.Integer, primary_key=True, index=True)
  39. username = sa.Column(sa.String, unique=True, nullable=False)
  40.  
  41. photo = sa.Column(sa.String, unique=True, nullable=True)
  42. user_id = sa.Column(sa.Integer, sa.ForeignKey('users.id'))
  43. events = relationship(
  44. Event,
  45. secondary=AccountEventAssociation,
  46. back_populates='accounts',
  47. )
Advertisement
Add Comment
Please, Sign In to add comment