Datastore的datetimeproperty可迭代吗?
我有一个模型
class info(db.Model):
user = db.UserProperty()
last_update_date = db.DateTimeProperty()
我需要获取特定用户的 last_update_date
。这个功能运行得很好,我可以顺利获取这个值,甚至可以把它传递给另一个变量
if results:
for result in results:
data = result.last_update_date
问题出现在我尝试把它赋值给
feed_uri = contacts.GetFeedUri()
feed_query = gdata.contacts.service.ContactsQuery(feed_uri)
feed_query.updated_min = data
这个操作是在任何循环之外进行的,所以我不明白为什么会提示说 datetime 不能被迭代。收到的错误信息是
追踪信息(最近的调用在最前面): 文件 "C:\Program Files (x86)\Google\google_appengine\google\appengine\ext\webapp__init__.py",第 507 行,在 call 中 handler.get(*groups) 文件 "C:\Users\mklich\workspace\google_contacts_webapp\src\contacts-list.py",第 266 行,在 get 中 listc = checkUserPrivateContacts(user) 文件 "C:\Users\mklich\workspace\google_contacts_webapp\src\contacts-list.py",第 189 行,在 checkUserPrivateContacts 中 feed = contacts.GetContactsFeed(feed_query.ToUri()) 文件 "C:\Users\mklich\workspace\google_contacts_webapp\src\gdata\service.py",第 1718 行,在 ToUri 中 return atom.service.BuildUri(q_feed, self) 文件 "C:\Users\mklich\workspace\google_contacts_webapp\src\atom\service.py",第 584 行,在 BuildUri 中 parameter_list = DictionaryToParamList(url_params, escape_params) 文件 "C:\Users\mklich\workspace\google_contacts_webapp\src\atom\service.py",第 551 行,在 DictionaryToParamList 中 for param, value in (url_parameters or {}).items()] 文件 "C:\Python25\lib\urllib.py",第 1210 行,在 quote_plus 中 if ' ' in s: 类型错误:类型 'datetime.datetime' 的参数不可迭代
我是不是做错了什么,还是这是个bug?谢谢大家的回复。
1 个回答
这是来自联系人API文档的一个例子:
updated_min = raw_input('Enter updated min (example: 2007-03-16T00:00:00): ')
query = gdata.contacts.service.ContactsQuery()
query.updated_min = updated_min
我觉得updated_min
这个属性应该是接收一个字符串,而不是一个datetime
对象。