python - 如何使用 web2py.DAL 进行 'between' 查询?

标签 python web2py

我正在尝试创建一个接受两个 datetime.date 对象(start_date 和 end_date)的查询函数,并返回具有介于 start_date 和 end_date 之间的相关字段的所有记录。 但是,我在 web2py 手册中找不到类似 between 函数的东西,所以我这样实现它:

        for o in objects:
            # notice that create_time is a datetime field
            create_date = dt.datetime.strptime(o['create_time'], 
                                               "%Y-%m-%d %H:%M:%S").strftime("%Y-%m-%d")
        if query_dict['create_date_1'] <= create_date <= query_dict['create_date_2']:
            result.append(l)

这样做对我的应用程序来说太慢了,因为它们可能有很多对象。 那么,有没有更好的方法可以使用 web2py.DAL 来实现它? 提前致谢;)

最佳答案

db((db.mytable.create_date>=query_dict['create_date1'])&(db.mytable.create_date<=query_dict['create_date2'])).select()

关于python - 如何使用 web2py.DAL 进行 'between' 查询?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1907088/

相关文章:

python - 从对象检测 API 中使用的 TFRecord 文件中读取数据

python - 在计算地球上各点之间的距离时,为什么我的 Haversine 与 Geodesic 计算结果不同?

python - 发送没有 "returning"的 HttpResponse(status=200) - 发送到哪里?

python - 在模板 Django 中获取 Site_ID

python - 带参数的 Web2py Controller ?

python - Openstack远程调试

python - decision_tree_regressor 模型的负 cross_val_score

python - web2py 有这些吗?

php - lighttpd 上的 web2py 和 wordpress

web2py - 获取所有登录用户Web2py