app-engine-ndb

ndb Model - retrieve ordered set of property names

心不动则不痛 提交于 2019-12-10 19:45:07
问题 I'm often asked to export data stored in NDB models to csv. For that purpose, I usually ended up writing a model like this: from google.appengine.ext import ndb class Foo(ndb.Model): monty = ndb.StringProperty() python = ndb.StringProperty() @property @classmethod def fieldnames(cls): return ['monty', 'python'] and in the export module something along the lines of # pseudocode ... query = Foo.gql('where monty = :1', 'bunny') data = [littlefoo._to_dict() for littlefoo in query] fieldnames =

Workaround to return a list from a ComputedProperty function in NDB

元气小坏坏 提交于 2019-12-10 17:53:31
问题 I am converting my app to use NDB. I used to have something like this before: @db.ComputedProperty def someComputedProperty(self, indexed=False): if not self.someCondition: return [] src = self.someReferenceProperty list = src.list1 + src.list2 + src.list3 + src.list4 \ + [src.str1, src.str2] return map(lambda x:'' if not x else x.lower(), list) As you can see, my method of generating the list is a bit complicated, I prefer to keep it this way. But when I started converting to NDB, I just

Get NDB query length - using Python on Google App Engine

廉价感情. 提交于 2019-12-10 15:08:26
问题 What is a good way to get the number of query result when using NDB on google app engine? Attempted this: query = NDB_Model.query(NDB_Model.some_property == some_value) if len(query) > 0: # <-- this throws and exception entity = query[0] I apologize that this is probably a very simple question, but it was not clear to me from the docs. 回答1: It seems like you just want to get the first entity from your query. That's what query.get() is for. query = NDB_Model.query(NDB_Model.some_property ==

GAE put_multi() entities using backend NDB

怎甘沉沦 提交于 2019-12-10 14:43:09
问题 I am using a backend to write multiple entities with ndb.put_multi(list_of_entities) . The issue that I am experiencing is that just after that if I make a query then I get no results. If I put a sleep timer for eg 1 sec, I can read the entities that I just wrote. So eg: class Picture(ndb.Expando): pass class Favourite(ndb.Expando): user_id = ndb.StringProperty(required=True) pass #...make lists with Picture and Favourite kinds entities = favourites entities[1:1] = pictures ndb.put_multi

GAE Appstats RPC Timeline graph shows long delays with complex NDB queries

别来无恙 提交于 2019-12-10 12:18:06
问题 I have attached the Appstats from my production app Search page below. The page takes ~45 seconds to load the results by AJAX. There are around 100 entities. The query is as shown below: qry_1 = X.query(ndb.AND(X.active_status=="active", X.property_3==input_3, X.property_4==input_4, X.property_5==input_5, X.property_6.IN(input_6_list), X.property_20.IN(input_20_list))) record_list = qry_1.fetch() # input_6_list contains ~5 string items # input_20_list contains ~5 string items I am not able to

NDB querying a GenericProperty in repeated Expando StructuredProperty

[亡魂溺海] 提交于 2019-12-10 10:42:32
问题 Hey guys im trying to figure out how to structure my query for the following case First i have a model defined class Variant(ndb.Expando): test = ndb.StringProperty() class Item(ndb.Model): test2 = ndb.StringProperty() variants = ndb.StructuredProperty(Variant, repeated=True) variant = Variant(test="test", dynamic="a") item = Item(test2="test", variants=[variant, ]) item.put() and then for the query stuff.. So far i've tried dynamic = "dynamic" Item.query(ndb.GenericProperty("variants.%s" %

NDB querying results that start with a string

依然范特西╮ 提交于 2019-12-10 10:21:00
问题 Working with Google App Engine's NDB, I'm looking to query for all items that start with a user-inputted string. Example: abc_123 abcdefg 123abc Querying for "abc" should return abc_123, abcdefg (however, not 123abc as it doesn't start with "abc") I previously used the code below for a similar but different purpose: q = q.filter(order._properties[kw].IN(values_list)) which filtered for all values in values_list that were in kw, I am now looking to filter for all values that start with a

How to flip to previous page with ndb cursors?

女生的网名这么多〃 提交于 2019-12-09 16:57:59
问题 I cant manage to get to 'previous page' in ndb paging. I have checked the documentation and also this similar question here without success. def show_feedback(kind, bookmark=None): """Renders returned feedback.""" cursor = None more_p= None if bookmark: cursor = Cursor(urlsafe=bookmark) q = Feedback.query() q_forward = q.filter(Feedback.kind==Feedback.KINDS[kind]).order(-Feedback.pub_date) q_reverse = q.filter(Feedback.kind==Feedback.KINDS[kind]).order(Feedback.pub_date) feedbacks, next

GAE python NDB projection query working in development but not in production

馋奶兔 提交于 2019-12-09 04:13:30
I've been hitting my head against the wall because my Google App Engine python project has a very simple NDB projection query which works fine on my local machine, but mysteriously fails when deployed to production. Adding to the mystery... as a test I added an identical projection on another property, and it works in both dev and production! Could anyone help please?! Here are more details: I have the following entity that represents an expense: class Entry(ndb.Model): datetime = ndb.DateTimeProperty(indexed=True, required=True) amount = ndb.IntegerProperty(indexed=False, required=True) payee

TransactionFailedError on GAE when no transaction

跟風遠走 提交于 2019-12-09 02:53:34
I got this error: TransactionFailedError: too much contention on these datastore entities. please try again. Even though I'm not doing any transactions. The line of my code that causes the error is ndb.put_multi(entity_list) # entity_list is a list of 100 entities This error doesn't happen often so it isn't a big deal, but I'm curious why I get this error. Any ideas? Here is most of the traceback: Traceback (most recent call last): ... File "/base/data/home/runtimes/python27_experiment/python27_lib/versions/1/google/appengine/ext/deferred/deferred.py", line 318, in post self.run_from_request()