| 3 | |
| 4 | |
| 5 | class NotificationUser(Base): |
| 6 | """ |
| 7 | |
| 8 | """ |
| 9 | |
| 10 | __tablename__ = 'notification_user' |
| 11 | |
| 12 | notification_id = Column(Integer, ForeignKey('notification.id'), primary_key=True) |
| 13 | notification = relationship("Notification", foreign_keys=[notification_id]) |
| 14 | |
| 15 | user_id = Column(Integer, ForeignKey('userbase.id'), primary_key=True) |
| 16 | user = relationship("User", foreign_keys=[user_id]) |
| 17 | |
| 18 | is_read = Column(Boolean, default=False) |
| 19 | |
| 20 | time_created = Column(DateTime, default=None, nullable=True) |
| 21 | |
| 22 | @staticmethod |
| 23 | def new(session=None, |
| 24 | add_to_session=False, |
| 25 | flush_session=False, |
| 26 | notification_id=None, |
| 27 | user_id=None, |
| 28 | is_read=False): |
| 29 | |
| 30 | notification = NotificationUser( |
| 31 | notification_id=notification_id, |
| 32 | user_id=user_id, |
| 33 | is_read=is_read) |
| 34 | if add_to_session: |
| 35 | session.add(notification) |
| 36 | if flush_session: |
| 37 | session.flush() |
| 38 | return notification |
| 39 | |
| 40 | @staticmethod |
| 41 | def get_by_id(session, notification_id=None, user_id=None): |
| 42 | return session.query(NotificationUser).filter( |
| 43 | NotificationUser.notification_id == notification_id, |
| 44 | NotificationUser.user_id == user_id |
| 45 | ).first() |
| 46 | |