Google app engine: problem with autoload reference keys!
I have a model Image that has a propery named "uploaded_by_user" that is a db.ReferenceProperty for the User model. When I query for the image in the "uploaded by user" property I already have the user value as a model.. I don't want that, I just want the key. I don't want that extra query to load the user. Is that possible?
EDIT1:
the array of images then is sent over PYAMF to flex. So the items must contain all data necessary.
EDIT2
Error:
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\e开发者_开发技巧xt\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'
No more this error! instead of saving over the item.uploaded_by_user I save on item.uploaded_by_user_key. But The item.uploaded_by_user still loads the User model..
item.uploaded_by_user_key = str(Image.uploaded_by_user.get_value_for_datastore(item))
item is my Image in this case. As image inherents from item I call it item.
class Image(db.Model):
uploaded_by_user= db.ReferenceProperty(User)
class User(db.Model):
...
You could do:
image = db.get(image_key)
user_id = Image.uploaded_by_user.get_value_for_datastore(image).id()
精彩评论