Created
July 9, 2014 10:41
-
-
Save GaretJax/a938c87826e232fd1eeb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Shop(Base): | |
| __tablename__ = 'shop_config' | |
| id = Column('site_id', Integer, primary_key=True) | |
| class Order(Base): | |
| __tablename__ = 'shop_order' | |
| id = Column(Integer, primary_key=True) | |
| site_id = Column(Integer) | |
| class AbstractStatus(object): | |
| id = Column(Integer, primary_key=True) | |
| time_stamp = Column(DateTime(timezone=True)) | |
| status = Column(String) | |
| notes = Column(Unicode(100)) | |
| @declared_attr | |
| def order_id(cls): | |
| return Column(Integer, ForeignKey(Order.id)) | |
| class Status(AbstractStatus, Base): | |
| __tablename__ = 'shop_orderstatus' | |
| order = relationship(Order, backref=backref( | |
| 'statuses', lazy=True, | |
| order_by=AbstractStatus.time_stamp.desc() | |
| )) | |
| class CurrentStatus(AbstractStatus, Base): | |
| """ | |
| This is a mapped view which holds the last status for each order. | |
| """ | |
| __tablename__ = 'shop_orderstatus_current' | |
| order = relationship(Order, backref=backref( | |
| 'current_status', lazy=False, uselist=False | |
| )) | |
| Shop.orders = relationship( | |
| Order, viewonly=True, lazy='dynamic', | |
| primaryjoin=((Shop.id == foreign(Order.site_id)) & (Order.status != '')), | |
| order_by=lambda: Order.current_status.timestamp, # <-- What can I put here to order by the current timestamp? | |
| ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment