Or how can I make this work work?
I have an Interval object:
class Interval(Base): __tablename__ = 'intervals' id = Column(Integer, primary_key=True) start = Column(DateTime) end = Column(DateTime, nullable=True) task_id = Column(Integer, ForeignKey('tasks.id')) @hybrid_property #used to just be @property def hours_spent(self): end = self.end or datetime.datetime.now() return (end-start).total_seconds()/60/60
And the task:
class Task(Base): __tablename__ = 'tasks' id = Column(Integer, primary_key=True) title = Column(String) intervals = relationship("Interval", backref="task") @hybrid_property # Also used to be just @property def hours_spent(self): return sum(i.hours_spent for i in self.intervals)
Add, of course, all the typical installation codes.
Now when I try to do session.query(Task).filter(Task.hours_spent > 3).all()
I get NotImplementedError: <built-in function getitem> from the string sum(i.hours_spent...
So, I looked at this part of the documentation and suggested that there might be some way so that I can write something that will do what I want. This part also looks as if it could be useful, and I will look at it, waiting for an answer here;)
python null-coalescing-operator sqlalchemy
Wayne werner
source share