app-engine-ndb

In Google App Engine, how can I work with eventual consistency in handling form submissions?

时光总嘲笑我的痴心妄想 提交于 2019-12-19 08:41:10
问题 I've noticed that, with eventual consistency, the common form-processing workflow that I am used to (submit -> create/update record -> redirect -> reload) doesn't work. Upon redirect, the new record (probably) won't be available for display. How should I handle forms so that updates are displayed upon reload? I could try to use strong consistency, but as the App Engine documentation notes, updates are limited to one update per second. So how can I process a form providing immediate user

how to delete NDB entity using ID?

我们两清 提交于 2019-12-19 06:57:08
问题 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? 回答1: Try this: ndb.Key(category, int(id))

how to delete NDB entity using ID?

巧了我就是萌 提交于 2019-12-19 06:55:51
问题 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? 回答1: Try this: ndb.Key(category, int(id))

How to fix index error when querying GAE datastore?

孤人 提交于 2019-12-18 15:54:31
问题 When I try to run a query on the datastore ordered by date I get the following error: NeedIndexError: no matching index found. The suggested index for this query is: - kind: Message properties: - name: author - name: ref - name: date The query runs without error if I don't try to order by date. The appengine console under datastore indexes says: author ▲ , ref ▲ , date ▼ Serving What am I doing wrong? How can I run my query ordered by date? Thanks! Here is my entity definition: from google

How to structure movies database and user choices?

ε祈祈猫儿з 提交于 2019-12-18 13:42:18
问题 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

How to structure movies database and user choices?

懵懂的女人 提交于 2019-12-18 13:42:06
问题 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

Google Datastore queries and eventual consistency

只愿长相守 提交于 2019-12-18 13:27:57
问题 I would like to confirm my understanding of eventual consistency in the Google datastore. Suppose that I have an entity defined as follows (using ndb): class Record(ndb.Model): name = ndb.StringProperty() content = ndb.BlobProperty() I think I understand Scenarios 1, but I have doubts about Scenarios 2 and 3, so some advice would be highly appreciated. Scenario 1: I insert a new Record with name "Luca" and a given content. Then, I query the datastore: qry = Record.query(name=="Luca") for r in

Google App Engine (Python) - Uploading a file (image)

你说的曾经没有我的故事 提交于 2019-12-18 11:13:35
问题 I want the user to be able to upload images to Google App Engine. I have the following (Python): class ImageData(ndb.Model): name = ndb.StringProperty(indexed=False) image = ndb.BlobProperty() Information is submitted by the user using a form (HTML): <form name = "input" action = "/register" method = "post"> name: <input type = "text" name = "name"> image: <input type = "file" name = "image"> </form> Which is then processed by: class AddProduct(webapp2.RequestHandler): def post(self):

BadRequestError: app s~myapphr cannot access app dev~myapphr's data. Why?

白昼怎懂夜的黑 提交于 2019-12-17 16:51:01
问题 I am using the Python 2.7 runtime with NDB from the 1.6.2 SDK on Google App Engine. I get the following error: BadRequestError: app s~myapphr cannot access app dev~myapphr's data Originating from this code: device = model.Key(urlsafe=device_id).get() I am accessing my app from dev.myapp.appspot.com that is aliased to myapphr. device_id was created on the same dev.myapphr version. What is going on? 回答1: the dev server has a default default_partition of 'dev' and on production, HRD apps get a

App Engine BadValueError when saving ndb LocalStructured entity

泪湿孤枕 提交于 2019-12-14 03:54:13
问题 I have the models class Foo(ndb.Model): x = ndb.IntegerProperty() class Bar(ndb.Model): foo = ndb.StructuredProperty(Foo, repeated=True) I keep getting lately, when trying to save Bar entities, only in production, this error: BadValueError: Expected Foo instance, got Foo(x=100) I remember seeing this error a while ago, and then it dissapeared. What's the reason for this? 回答1: The problem was I was using relative imports for models.py in the file where I was saving the model, so somehow python