app-engine-ndb

Query google app engine datastore for all entities

一世执手 提交于 2019-12-25 02:25:08
问题 Given this model class class Student(ndb.Model): student_id = ndb.IntegerProperty(required=True) student_name = ndb.StringProperty(required=True) score=ndb.IntegerProperty(required=True) def toJSON(self): jsonData = { "Student Id":str(self.student_id), "Name":self.student_name, "Score": str(self.score) } return json.encode(jsonData) I am trying to run a query to return all the student names, along with the score for each student in JSON format. I already ran a query on the datastore and was

Working with ancestors in GAE

可紊 提交于 2019-12-24 18:53:24
问题 I only want that someone confirm me that I'm doing things in the right way. I have this structure: Books that have Chapters (ancestor=Book) that have Pages (ancestor=Chapter) It is clear for me that, to search for a Chapter by ID, I need the book to search by ancestor query. My doubt is: do I need all the chain book-chapter to search a page? For example (I'm in NDB): class Book(ndb.Model): # Search by id @classmethod def by_id(cls, id): return Book.get_by_id(long(id)) class Chapter(ndb.Model)

How to get latest and adjacent records from the datastore?

六月ゝ 毕业季﹏ 提交于 2019-12-24 17:55:57
问题 I have movies datastore, each record there has its own id as key name like below: 12345 32453 12154 78873 34543 I would like to allow user to browse movies one by one. Firstly, the latest movie should be shown (database has field added with date and time). How to get that from the datastore? Upd. I can do it like below: movies = Movies.query() movies.order(-Movies.added) for movie in movies.fetch(1): self.response.out.write(movie.key.id()) But I don't like it - in order to get key I request

How to search structured properties ? google app engine

爱⌒轻易说出口 提交于 2019-12-24 13:03:12
问题 I have two models categories and cities: class category(ndb.Model): hidden = ndb.BooleanProperty() categoryName = ndb.StringProperty() class city(ndb.Model): categories = ndb.StructuredProperty(category,repeated = True) cityName = ndb.StringProperty() I have cityEntity: How to return categories list that contain just category.hidden = false ? edit: it's possible to get the categories list, then Loop through the categories list and extract just the categories which not hidden for example I

TextProperty field in NDB gets “=” appended after every line

我怕爱的太早我们不能终老 提交于 2019-12-24 11:15:53
问题 I have very strange case which I wasn't able to debug for a day. On my front-end I have form with textarea and submit button. On submission, the textarea field gets saved as ndb.TextProperty() When I submit a multiline text, the text in the database gets = or =20 characters on every line. At first I thought they get randomly inserted, but it seems every 76 characters gets one = character. This gets really hard to debug as on my localhost instance it works perfectly fine, but on the deployed

GAE Python NDB .put not synchronous on development (but works in production)?

大兔子大兔子 提交于 2019-12-24 10:50:55
问题 The following below should create a Counter model and use (deferred) tasks to increment the counter to 10. Visiting '/' ought to create a single Counter object with count = 10 . This happens in production. In development (localhost) multiple Counter objects are created with the largest being 10: I suspect this is because the put is not synchronous on development (but appears to always be on production). Is there a way to make them synchronous? Code snippet below: class Counter(ndb.Model):

NDB Query builder doesn't work as expected

眉间皱痕 提交于 2019-12-24 06:47:19
问题 I have the following query in my application query = cls.query().filter(cls.taskgroup_id == taskgroup_id, cls.availability == True, cls.task_id > min_task_id).order(cls.task_id) query.fetch(1) Above works fine as expected. (Fetches only those entities, which match taskgroup_id, and is available, and task_id > min_task_id) However, when I break query into multiple statements. query = cls.query() query.filter(cls.taskgroup_id == taskgroup_id) query.filter(cls.availability == True) query.filter

New entity in repeated StructuredProperty stored as a _BaseValue

我是研究僧i 提交于 2019-12-24 04:59:24
问题 I have a HUser model (derived from Google's User class) which in turn contains 0 to n instances of social accounts. These accounts can be references to Facebook, Twitter or LinkedIn accounts. I have built an Account model, and defined a StructuredProperty in my User model with repeated=True , like this: class Account(ndb.Expando): account_type = ndb.StringProperty(required=True, choices=['fb', 'tw', 'li']) account_id = ndb.StringProperty() access_token = ndb.StringProperty() ... class HUser

How efficient is Google App Engine ndb.delete_multi()?

限于喜欢 提交于 2019-12-24 04:41:29
问题 I'm working on something to clear my database of ~10,000 entities, and my plan is to put it in a task that deletes 200 at a time using ndb.delete_multi() and then recursively calls itself again until there are no entities left. For now, I don't have the recursion in it yet so I could run the code a few times manually and check for errors, quota use, etc. The code is: entities = MyModel.query_all(ndb.Key('MyModel', '*defaultMyModel')).fetch(200) key_list = ndb.put_multi(entities) ndb.delete

How automatic NDB caching works?

孤街醉人 提交于 2019-12-24 01:15:54
问题 My website is movies catalog. Once user log in, I show him/her the latest movie added to my database: movies = Movies.query() movies = movies.order(-Movies.added) movie = movies.get(keys_only = True) // get_latest_movie_id Is it cached (movies are added to the database weekly, so it should be cached)? How to verify that (i.e. what is memcache key)? Yesterday about 1000 users visited my site and I've got OverQuotaError: The API call datastore_v3.RunQuery() required more quota than is available