下面是 python 代码,我试图从预订模型中获取预订信息。
i=0
for c in courts:
court = names[i]
i=i+1
c_key=c.key()
logging.info("c_key: %s " % c_key)
weekday_key= db.Key.from_path('Courts', 'c_key', 'Days', weekday)
logging.info("weekday_key: %s " % weekday_key)
logging.info("weekday: %s " % weekday)
logging.info("court: %s " % court)
reservation = db.Query(Reservations)
nlimit=2*len(times)
reservations = reservation.fetch(limit=nlimit)
logging.info("reservations: %s " % len(reservations))
我的 Courts 数据库中只有两个法院实体,court1 和 court2。在我的 Days 数据库中也只有 14 个工作日实体,7 个用于 court1,7 个用于 court2,名为 Sunday, ... , Saturday。在当前示例中,我试图获取 2 个星期一的密钥,一个用于 court1,一个用于 court2。weekday_key
我不明白为什么根据下面的日志,对于两个拥有不同钥匙的不同法院,我得到的结果是一样的c_key
。
在下面的日志中,无论我输入db.Key.from_path(
命令 'c_key' 还是 'court' 我都会得到完全相同的结果,这表明 2weekday_key
的值是相同的,而不是我预期的不同。
INFO 2012-09-10 21:25:19,189 views.py:226] c_key: ag1kZXZ-c2NoZWR1bGVycicLEglMb2NhdGlvbnMiBlJvZ2VycwwLEgZDb3VydHMiBmNvdXJ0MQw
INFO 2012-09-10 21:25:19,189 views.py:228] weekday_key: ag1kZXZ-c2NoZWR1bGVyciELEgZDb3VydHMiBWNfa2V5DAsSBERheXMiBk1vbmRheQw
INFO 2012-09-10 21:25:19,189 views.py:229] weekday: Monday
INFO 2012-09-10 21:25:19,189 views.py:230] court: court1
INFO 2012-09-10 21:25:19,192 views.py:235] reservations: 1
INFO 2012-09-10 21:25:19,192 views.py:226] c_key: ag1kZXZ-c2NoZWR1bGVycicLEglMb2NhdGlvbnMiBlJvZ2VycwwLEgZDb3VydHMiBmNvdXJ0Mgw
INFO 2012-09-10 21:25:19,192 views.py:228] weekday_key: ag1kZXZ-c2NoZWR1bGVyciELEgZDb3VydHMiBWNfa2V5DAsSBERheXMiBk1vbmRheQw
INFO 2012-09-10 21:25:19,192 views.py:229] weekday: Monday
INFO 2012-09-10 21:25:19,192 views.py:230] court: court2
INFO 2012-09-10 21:25:19,195 views.py:235] reservations: 1
我的模型如下。
class Courts(db.Model): #parent is Locations, courtname is key_name
location = db.ReferenceProperty(Locations)
timezone = db.StringProperty()
class Days (db.Model): #parent is Courts, name is key_name, day of week
court = db.ReferenceProperty(Courts)
startTime = db.ListProperty(int)
endTime = db.ListProperty(int)
class Reservations(db.Model): #parent is Days, hour, minute HH:MM is key_name
weekday = db.ReferenceProperty(Days)
day = db.IntegerProperty()
nowweekday = db.IntegerProperty()
name = db.StringProperty()
hour = db.IntegerProperty()
minute = db.IntegerProperty()