python - 两个不同日期字段的不等式查询

标签 python google-app-engine google-cloud-datastore

我正在使用 Google App Engine 使用 Python 开发一个应用程序。 在我的申请中,我应该保存学生的缺勤及其理由,所以我有一个类(class):

class Absence(ndb.Model):
    day_begin = ndb.DateProperty(required=True)
    day_end = ndb.DateProperty(required=True)
    justified = ndb.BooleanProperty()
    date_range =  ndb.ComputedProperty(lambda self: generate_date_range(self.day_begin, self.day_end), repeated=True)
    student = ndb.KeyProperty(kind=SchoolUser, required=True)

对于每一天,老师都可以看到所有缺勤的学生,因此我必须使用 day_begin <= Today <= day_end 查询所有缺勤。由于我无法使用多个不等式过滤器进行查询,因此现在我将范围内的所有日期保存在字段 date_range 中,然后对其进行查询。 我想知道这种方法是否高效有效,或者是否有更好的解决方案? 谢谢!!!

最佳答案

这是一个合理的解决方案,具体取决于您期望在数据和查询过滤器中看到的范围。 App Engine FTS 解决方案执行类似于支持数字类型的操作。如果遇到性能问题,您也许可以通过多个粒度级别(例如天、月、年)来改进它。

地理空间查询遇到了同样的问题。他们使用空间填充曲线来解决这个问题,请参阅https://code.google.com/p/s2-geometry-library-java/ .

关于python - 两个不同日期字段的不等式查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16613067/

相关文章:

python - 带有 ListDirectory 的 Tensorflow 数据集 API

java - 我正在寻找使用 app-engine 进行 Java 编程的好读物

google-app-engine - 谷歌应用引擎 API : Running large tasks

java - 如何将自定义唯一编号分配给 GAE 中的实体?

python - 如何内省(introspection) App Engine 数据存储模型?

google-cloud-datastore - 从 Google Cloud Firestore 恢复到 Datastore

python - 如何管理大文件?

python - 将通过网络收到的 python 字符串 (FIX) 解释为二进制

python - 按当前日期前一周的日期过滤数据框

python - 使用 ndb.blobproperty 引发的值错误