app-engine-ndb

How to query with a list object on repeated string property in ndb

久未见 提交于 2019-12-11 08:59:08
问题 With google app engine, I use ndb to manange my data. I have a entity that use a repeated string property to save a list of string values. How can I query with a list object that is equal to the property value? What I meant is, the entity is class Question(ndb.Model): question = ndb.StringProperty(required=True) choices = ndb.StringProperty(repeated=True) and I want to query like this: question = "The question" choices = ["Choice1", "Choice2", ..., "Choice6"] Question.query(Question.question=

Adding a StructuredProperty to a Model in NDB

℡╲_俬逩灬. 提交于 2019-12-11 08:44:02
问题 (couldn't think of a better title :S ) So I've recently changed from db to ndb and i can't get one part to work. I have this tutorial model that has chapters, so I am using 'ndb.StructuredProperty' to associate the model Chapter to the tutorial. I can create the tutorials and the chapter with no problems but i can't point the chapters to the tutorial. The Tutorial Model: class Tutorial(ndb.Model): title = ndb.StringProperty(required=True) presentation = ndb.TextProperty(required=True) extra1

NDB ordering by property of StructuredProperty

ⅰ亾dé卋堺 提交于 2019-12-11 06:35:39
问题 Say I have an ndb.Model class that I want to use as a StructuredProperty on another model class: class CommonExtraData(ndb.Model): count = ndb.IntegerProperty(required=True) class MyObject(ndb.Model): name = ndb.StringProperty(required=True) extra = ndb.StructuredProperty(CommonExtraData, required=True) Could I then do a query like this: MyObject.query().order(-MyObject.extra.count) I can't find an example in the docs, and my dev environment is not currently working due to my endeavors of

Figure out group of tasks completion time using TaskQueue and Datastore

风格不统一 提交于 2019-12-11 05:36:29
问题 I have a push task queue and each of my jobs consists of multiple similar TaskQueue tasks. Each of these tasks takes less than a second to finish and can add new tasks to the queue (they should be also completed to consider the job finished). Task results are written to a DataStore. The goal is to understand when a job has finished, i.e. all of its tasks are completed. Writes are really frequent and I can't store the results inside one entity group. Is there a good workaround for this? 回答1:

Optimizing a inequality query in ndb over two properties

流过昼夜 提交于 2019-12-11 05:14:24
问题 I'm trying to do a query into a range of valid dates q = Licence.query(Licence.valid_from <= today, Licence.valid_to >= today, ancestor = customer.key ).fetch(keys_only=True) I know that Datastore doesn't support inequality queries over two propperties. So I do this: kl = Licence.query(Licence.valid_from <= today, ancestor = customer.key ).fetch(keys_only=True) licences = ndb.get_multi(kl) for item in licences: if item.valid_to < today: licence.remove(item) But I don't like because I think

geoSpatial & Location based search in google appengine python

独自空忆成欢 提交于 2019-12-11 03:01:16
问题 I want to achieve something like the map drag search on airbnb (https://www.airbnb.com/s/Paris--France?source=ds&page=1&s_tag=PNoY_mlz&allow_override%5B%5D=) I am saving the data like this in datastore user.lat = float(lat) user.lon = float(lon) user.geoLocation = ndb.GeoPt(float(lat),float(lon)) and whenever I drag & drop map or zoom in or zoom out I get following parameters in my controller def get(self): """ This is an ajax function. It gets the place name, north_east, and south_west

Weird query comparison of GeoPt in google ndb

匆匆过客 提交于 2019-12-11 02:12:40
问题 I try to query entities in datastore with GeoProperty, but the strange thing is it will compare GeoProperty's first argument, lat. If lat is compared, then it will directly return the result. The only exception is latitude is equal, then the longitude is then compared. For example, GeoPt(11, 10) < GeoPt(9, 20) will return False because former latitude is not smaller than latter. However, latter is bigger than former. SO this kind of comparison bother me when I want to query the entities in

How to use ndb key with integer_id?

泪湿孤枕 提交于 2019-12-11 00:09:48
问题 I see the document https://developers.google.com/appengine/docs/python/ndb/keyclass#Key_integer_id Returns the integer id in the last (kind, id) pair, or None if the key has an string id or is incomplete. see I think the id of a key can be a int ; so I write r = ndb.Key(UserSession, int(id)).get() if r: return r.session but the dev_server.py , will always raise File "/home/bitcoin/down/google_appengine/google/appengine/datastore/datastore_stub_util.py", line 346, in CheckReference raise

Change on indexed=False to True not realized by DataStorage and query

橙三吉。 提交于 2019-12-10 23:07:30
问题 Inside my model I had a property that was set to indexed=False . To use it in a projection I had to change this to indexed=True . But surprisingly now doing a query does not give a single result, always empty. Any hint to reindex the table or why the result set is empty? https://developers.google.com/appengine/docs/python/ndb/properties#options 回答1: For data that was saved before you changed indexed from False to True, any indexes will not include that property. You need to save each of your

Proper way to migrate NDB model property

情到浓时终转凉″ 提交于 2019-12-10 21:51:24
问题 I currently have a model in NDB and I'd like to change the property name without necessarily touching NBD. Let's say I have the following: from google.appengine.ext import ndb class User(ndb.Model): company = ndb.KeyProperty(repeated=True) What I would like to have is something more like this: class User(ndb.Model): company_ = ndb.KeyProperty(repeated=True) @property def company(self): return '42' @company.setter def company(self, new_company): #set company here Is there a relatively pain