app-engine-ndb

GAE: AssertionError: No api proxy found for service “datastore_v3”

梦想的初衷 提交于 2019-12-01 05:48:59
问题 I'm writing simple to code to access dev server. Both dev server and datastore emulated have been started locally. from google.appengine.ext import ndb class Account(ndb.Model): name = ndb.StringProperty() acc = Account(name=u"test").put() print(acc) Error: AssertionError: No api proxy found for service "datastore_v3" I tried to set: export DATASTORE_EMULATOR_HOST=localhost:8760 . It does not help. $ dev_appserver.py ./app.yaml WARNING 2017-02-20 06:40:23,130 application_configuration.py:176]

how to delete NDB entity using ID?

馋奶兔 提交于 2019-12-01 05:19:23
based on this docs https://developers.google.com/appengine/docs/python/ndb/entities#deleting_entities well, im still not sure why i cannot do the delete on NDB: def get(self): id = self.request.get("delete") ndb.Key('category', id).delete() yeah i know how to select using id ndb.Key('category', id).get() but its still not working... key = ndb.Key('category', id).get() key.delete() this one also not working: category.key.delete() something wrong? Try this: ndb.Key(category, int(id)).delete() You need to convert the id to integer in order to build a numeric (id) key instead of a name key. 来源:

One-To-Many Example in NDB

白昼怎懂夜的黑 提交于 2019-12-01 04:02:45
I am trying to create ndb.Model class like Students and subjects class Subject(ndb.Model): name = ndb.StringProperty() class Student(ndb.Model): name = ndb.StringProperty() subject = ndb.KeyProperty(kind=Subject) One Student can have many Subjects. How to add and store these in this Model. I could not find any example of it. For String Property .. there is field property i.e. repeat=true How to achieve this and is there any working example on the web. Sorry if it is duplicate question but I tried with my limited skills to search this forum. When I need 1 to many I use repeated keyProperties.

Google App Engine NDB custom key id

别等时光非礼了梦想. 提交于 2019-11-30 17:05:26
When I create an object with ndb's method put it creates the key automatically of the type Key(kind, id) where id is a number. All over the documentation it shows that you can use a string for the key's id but I couldn't find out how to do this automatically when an object is created. I have a User model and I was thinking to use the user's username (since its unique) as the key's id for faster retrieval. Is that even a good idea? Would I have any problems with the username since it's user submited (i'm validating the input)? class UserModel(ndb.Model): ... user_model_entity = UserModel(id=

NDB not clearing memory during a long request

[亡魂溺海] 提交于 2019-11-30 15:20:04
问题 I am currently offloading a long running job to a TaskQueue to calculate connections between NDB entities in the Datastore. Basically this queue handles several lists of entity keys that are to be related to another query by the node_in_connected_nodes function in the GetConnectedNodes node: class GetConnectedNodes(object): """Class for getting the connected nodes from a list of nodes in a paged way""" def __init__(self, list, query): # super(GetConnectedNodes, self).__init__() self.nodes =

Google Appengine NDB ancestor vs key query

断了今生、忘了曾经 提交于 2019-11-30 15:08:28
问题 I am storing a key of an entity as a property of another in order to relate them. We are in a refactor stage at this point in the project so I was thinking about introducing ancestors. Is there a performance difference between the two approaches? Any given advantages that I might gain if we introduce ancestors? class Book(ndb.Model): ... class Article(ndb.Model): book_key = ndb.KeyProperty(kind=Book, required=True) book_key = ndb.Key("Book", 12345) 1st ancestor query approach qry = Article

NDB not clearing memory during a long request

牧云@^-^@ 提交于 2019-11-30 14:21:48
I am currently offloading a long running job to a TaskQueue to calculate connections between NDB entities in the Datastore. Basically this queue handles several lists of entity keys that are to be related to another query by the node_in_connected_nodes function in the GetConnectedNodes node: class GetConnectedNodes(object): """Class for getting the connected nodes from a list of nodes in a paged way""" def __init__(self, list, query): # super(GetConnectedNodes, self).__init__() self.nodes = [ndb.model.Key('Node','%s' % x) for x in list] self.cursor = 0 self.MAX_QUERY = 100 # logging.info('Max

How to query parent entity from child entity in Google App Engine (Python) NDB/Datastore?

纵饮孤独 提交于 2019-11-30 13:53:10
问题 My question is very fundamental, I want to know straight forward and right way to access attribute values of parent entity from a child in App Engine Python. For example I have following model schema. I am using Python 2.7 and NDB. class Gallery(ndb.Model): category = ndb.StringProperty() title = ndb.StringProperty() subtitle = ndb.StringProperty() class Image(ndb.Model): blob_key = ndb.BlobKeyProperty() title = ndb.StringProperty() gallery = ndb.StringProperty() is_slider = ndb

Google Appengine NDB ancestor vs key query

大憨熊 提交于 2019-11-30 12:55:33
I am storing a key of an entity as a property of another in order to relate them. We are in a refactor stage at this point in the project so I was thinking about introducing ancestors. Is there a performance difference between the two approaches? Any given advantages that I might gain if we introduce ancestors? class Book(ndb.Model): ... class Article(ndb.Model): book_key = ndb.KeyProperty(kind=Book, required=True) book_key = ndb.Key("Book", 12345) 1st ancestor query approach qry = Article.query(ancestor=book_key) 2st simple key query approach qry = Article.query(book_key=book_key) The

How to structure movies database and user choices?

倖福魔咒の 提交于 2019-11-30 10:23:20
I would like to create movies database, where user will be able to mark movies he/she watched and liked: class Movies(ndb.Model): watched = ndb.UserProperty() liked = ndb.UserProperty() Will that work? I use Google accounts. How should I choose later all movies user liked? Upd . I've followed systempuntoout approach and use the following code to save user choices: user = users.get_current_user() if user: userschoices = models.UsersChoices( movie=ndb.Key(models.Movies, movie_id), # TODO: what if movie_id is wrong? watched=True, user_id=user.user_id() ) try: userschoices.put() self.response.out