我有一个模型Image,其中有一个名为“uploaded_by_user”的属性,它是User模型的db.ReferenceProperty。当我在“用户上传”属性中查询图像时,我已将用户值作为模型..我不想要那个,我只想要密钥。我不希望额外的查询加载用户。这可能吗?
然后通过PYAMF将图像数组发送到flex。因此,项目必须包含所有必要的数据。
错误:
Traceback (most recent call last):
, File "D:\Totty\webDevelopment\TottysWorld\src\pyamf\remoting\amf0.py", line 108, in __call__
*args, **kwargs)
, File "D:\Totty\webDevelopment\TottysWorld\src\pyamf\remoting\amf0.py", line 61, in _getBody
**kwargs)
, File "D:\Totty\webDevelopment\TottysWorld\src\pyamf\remoting\gateway\__init__.py", line 510, in callServiceRequest
return service_request(*args)
, File "D:\Totty\webDevelopment\TottysWorld\src\pyamf\remoting\gateway\__init__.py", line 233, in __call__
return self.service(self.method, args)
, File "D:\Totty\webDevelopment\TottysWorld\src\pyamf\remoting\gateway\__init__.py", line 133, in __call__
return func(*params)
, File "D:\Totty\webDevelopment\TottysWorld\src\app\services\lists\get_contents.py", line 39, in get_contents
item.uploaded_by_user = str(Image.uploaded_by_user.get_value_for_datastore(item))
, File "C:\GAE\google\appengine\ext\db\__init__.py", line 3216, in __set__
value = self.validate(value)
, File "C:\GAE\google\appengine\ext\db\__init__.py", line 3246, in validate
if value is not None and not value.has_key():
,AttributeError: 'str' object has no attribute 'has_key'
不再是这个错误!而不是保存在item.uploaded_by_user上我保存在item.uploaded_by_user_key上。但是item.uploaded_by_user仍然加载用户模型..
item.uploaded_by_user_key = str(Image.uploaded_by_user.get_value_for_datastore(item))
在这种情况下,项目是我的图像。作为图像的内容来自项目我称之为项目。
答案 0 :(得分:0)
class Image(db.Model):
uploaded_by_user= db.ReferenceProperty(User)
class User(db.Model):
...
你可以这样做:
image = db.get(image_key)
user_id = Image.uploaded_by_user.get_value_for_datastore(image).id()