I have this class:
class Monitor(db.Model):
'''
Base Monitor class.
'''
__tablename__ = 'monitor'
id = db.Column(db.Integer(), primary_key=True)
last_checked = db.Column(db.DateTime(timezone=False))
poll_interval = db.Column(db.Interval(),
default=datetime.timedelta(seconds=300))
And I have this query where I attempt to return only objects that haven't been checked since (now - interval):
monitors = db.session.query(Monitor).\
filter(or_(Monitor.last_checked < (datetime.utcnow() - Monitor.poll_interval)),
Monitor.last_checked == None).\
all()
But the query returns nothing. I'm having a hard time figuring out the proper way to do this. Am I on the right track or am I missing something? I'm using MySQL as the database.
Your parenthesis are wrong. I believe what you want is:
monitors = db.session.query(Monitor).\
filter(or_(Monitor.last_checked < (datetime.utcnow() - Monitor.poll_interval),
Monitor.last_checked == None)).\
all()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With