现在已有对应的一个活动的列表
现在需要query时去filter检索出:
时间是当天的,明天的,一周内的,一周之外的
SQLAlchemy(二) — ORM – 作业部落 Cmd Markdown 编辑阅读器
sqlalchemy datetime filter
python – Doing DateTime Comparisons in Filter SQLAlchemy – Stack Overflow
python – sqlalchemy filter by comparing datetime.now() and column default date – Stack Overflow
sqlalchemy datetime filter between
SQLAlchemy ORM Examples | Python Central
sqlalchemy datetime today
datetime – Make Sqlalchemy Use Date In Filter Using Postgresql – Stack Overflow
python – SQLAlchemy default DateTime – Stack Overflow
Column Insert/Update Defaults — SQLAlchemy 1.1 Documentation
sqlalchemy filter by multiple
python – sqlalchemy filter multiple columns – Stack Overflow
[已解决]SQLAlchemy中filer_by中一次传入多个条件
至此,终于解决了:
通过:
dateFormat = “%Y-%m-%d” timeFormat = “%H:%M:%S” datetimeFormat = dateFormat + ” ” + timeFormat app.logger.debug(‘dateFormat=%s, timeFormat=%s, datetimeFormat=%s’, dateFormat, timeFormat, datetimeFormat) todayDatetime = datetime.today() todayDate = date.today() #todayDateStr = todayDatetime.strftime(dateFormat) todayDateStr = todayDate.strftime(dateFormat) app.logger.debug(‘todayDate=%s, todayDateStr=%s’, todayDate, todayDateStr) todayStartStr = todayDateStr + ” 00:00:00″ todayEndStr = todayDateStr + ” 23:59:59″ app.logger.debug(‘todayStartStr=%s, todayEndStr=%s’, todayStartStr, todayEndStr) todayStart = datetime.strptime(todayStartStr, datetimeFormat) todayEnd = datetime.strptime(todayEndStr, datetimeFormat) app.logger.debug(‘todayStart=%s, todayEnd=%s’, todayStart, todayEnd) #todayEventList = Event.query.filter_by(and_(user_openid=curUser.openid, start_date.date() = dateToday)).all() #todayEventList = Event.query.filter_by(and_(user_openid=curUser.openid, start_date >= todayStart, start_date <= todayEnd)).all() #todayEventList = Event.query.filter_by(and_(user_openid == curUser.openid, start_date >= todayStart, start_date <= todayEnd)).all() #todayEventList = Event.query.filter_by(user_openid=curUser.openid, start_date >= todayStart, start_date <= todayEnd).all() #todayEventList = Event.query.filter_by(and_(Event.user_openid == curUser.openid, Event.start_date >= todayStart, Event.start_date <= todayEnd)).all() todayEventList = Event.query.filter(and_(Event.user_openid == curUser.openid, Event.start_date >= todayStart, Event.start_date <= todayEnd)).all() app.logger.debug(“todayEventList=%s”, todayEventList) |
去过滤出,属于当天这个时间范围内的内容:
dateFormat=%Y-%m-%d, timeFormat=%H:%M:%S, datetimeFormat=%Y-%m-%d %H:%M:%S <div–<—————————————————————————— <div–<—————————————————————————— DEBUG in views [/root/html/SIPEvents/sipevents/views.py:385]: todayDate=2016-08-29, todayDateStr=2016-08-29 <div–<—————————————————————————— <div–<—————————————————————————— DEBUG in views [/root/html/SIPEvents/sipevents/views.py:388]: todayStartStr=2016-08-29 00:00:00, todayEndStr=2016-08-29 23:59:59 <div–<—————————————————————————— <div–<—————————————————————————— DEBUG in views [/root/html/SIPEvents/sipevents/views.py:391]: todayStart=2016-08-29 00:00:00, todayEnd=2016-08-29 23:59:59 <div–<—————————————————————————— <div–<—————————————————————————— DEBUG in views [/root/html/SIPEvents/sipevents/views.py:399]: todayEventList=[<Event id=5 user_openid=oswjmv4X0cCXcfkIwjoDfCkeTVVY title=u’\u4eca\u5929\u505a\u5f00\u53d1′>] |