このようなエンティティを 1 つの RequestHandler で保持し、SDK コンソールで確認できます。
class Moment(db.Model):
user = db.IntegerProperty()
index = db.IntegerProperty()
編集:以前は部分的なクラス定義のみを含め、モデルの作成方法を示していませんでした。以下は完全な例です。
class Moment(db.Model):
user = db.IntegerProperty()
index = db.IntegerProperty()
date = db.DateTimeProperty()
qx = db.FloatProperty()
qy = db.FloatProperty()
qz = db.FloatProperty()
qw = db.FloatProperty()
latitude = db.FloatProperty()
longitude = db.FloatProperty()
image = db.BlobProperty()
def __init__(self, obj):
super(Moment,self).__init__()
self.user = obj['user']
self.index = obj['index']
self.date = obj['date']
self.qx = obj['qx']
self.qy = obj['qy']
self.qz = obj['qz']
self.qw = obj['qw']
self.latitude = obj['latitude']
self.longitude = obj['longitude']
self.image = obj['image']
class UploadHandler(webapp2.RequestHandler):
def post(self):
obj = biplist.readPlistFromString(self.request.body)
Moment(obj).put()
フィルタリングして取得しようとすると...
class ServeHandler(webapp2.RequestHandler):
def get(self):
params = {}
params['user'] = int(self.request.get('user'))
params['index'] = int(self.request.get('index'))
q = Moment.all()
q.filter("user =", params['user'])
q.filter("index =", params['index'])
print q.get()
私は以下を取得します:
ERROR 2012-11-04 06:56:04,846 webapp2.py:1553] __init__() got an unexpected keyword argument 'index'
Traceback (most recent call last):
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webapp2/webapp2.py", line 1536, in __call__
rv = self.handle_exception(request, response, e)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webapp2/webapp2.py", line 1530, in __call__
rv = self.router.dispatch(request, response)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webapp2/webapp2.py", line 1278, in default_dispatcher
return route.handler_adapter(request, response)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webapp2/webapp2.py", line 1102, in __call__
return handler.dispatch()
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webapp2/webapp2.py", line 572, in dispatch
return self.handle_exception(e, self.app.debug)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webapp2/webapp2.py", line 570, in dispatch
return method(*args, **kwargs)
File "<path>/main.py", line 51, in get
print q.get()
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/ext/db/__init__.py", line 2102, in get
return results.next()
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/ext/db/__init__.py", line 2314, in next
return self.__model_class.from_entity(self.__iterator.next())
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/ext/db/__init__.py", line 1442, in from_entity
return cls(None, _from_entity=entity, **entity_values)
TypeError: __init__() got an unexpected keyword argument 'index'
INFO 2012-11-04 06:56:04,849 dev_appserver.py:3092] "GET /serve?user=0&index=0 HTTP/1.1" 500 -
ただし、print q.count()
代わりにprint q.get()
1を取得すると、ドキュメントに従って正しく動作しているようで、見つけた同様の質問から提案を試みましたが、役に立ちませんでした。
SDK v1.7.3