app-engine-ndb

What is the correct way to get the previous page of results given an NDB cursor?

℡╲_俬逩灬. 提交于 2019-12-03 02:04:32
I'm working on providing an API via GAE that will allow users to page forwards and backwards through a set of entities. I've reviewed the section about cursors on the NDB Queries documentation page , which includes some sample code that describes how to page backwards through query results, but it doesn't seem to be working as desired. I'm using GAE Development SDK 1.8.8. Here's a modified version of that example that creates 5 sample entities, gets and prints the first page, steps forward into and prints the second page, and attempts to step backwards and print the first page again: import

ndb to_dict method does not include object's key

拜拜、爱过 提交于 2019-12-02 17:41:33
I am leveraging ndb's to_dict method to convert an object's properties into a python dict. From everything I can tell, this method does not include the object's key or parent within the dict as per the documentation: https://developers.google.com/appengine/docs/python/ndb/modelclass#Model_to_dict However for my situation I need the key to be in the dict. My preference would be to leverage the builtin method and subclass it or something similar rather than create my own to_dict method. What is the best way to accomplish this or am I missing something obvious? Thanks in advance. FYI: I am not

jQuery Autocomplete with Remote JSON Source + Google App Engine + Python

假如想象 提交于 2019-12-02 17:04:36
问题 So let's say I have a webapp which just lets users save their hobbies. So I have Kind like this: class Hobby(ndb.Model): hobby_name = ndb.StringProperty() Users just create Hobby entities using this form: <form action="/new-hobby" method="post"> <input type="text" name="hobby_name" id="new-hobby" /> <input type="submit" value="Save New Hobby" /> </form> Then this form is handled by this: # Handles /new-hobby class NewHobby(webapp2.RequestHandler): def post(self): hobby_name = self.request.get

Linking to entity from list

社会主义新天地 提交于 2019-12-02 14:09:57
问题 I have a Consults page that lists consults in the datastore. The list loop is like this: {% for consult in consults %} <tr> <td><a href="consults/#">{{ consult.consult_date }}</a></td> <td>{{ consult.consult_time }}</td> <td>{{ consult.patient_first }}</td> <td>{{ consult.patient_last }}</td> <td><span class="badge badge-warning">{{ consult.consult_status }}</span></td> </tr> {%endfor%} The handler is like this: class ConsultsPage(webapp2.RequestHandler): def get(self): consults = Consults

app engine datastore transaction exception

橙三吉。 提交于 2019-12-02 10:06:15
In app engine transactions documentation I have found the following note: Note: If your app receives an exception when submitting a transaction, it does not always mean that the transaction failed. You can receive Timeout, TransactionFailedError, or InternalError exceptions in cases where transactions have been committed and eventually will be applied successfully. Whenever possible, make your Datastore transactions idempotent so that if you repeat a transaction, the end result will be the same. This is quite general information and I wasn't able to find more details. I have the following

Efficient way to store relation values in NDB

折月煮酒 提交于 2019-12-02 09:33:13
I've this data model (I made it, so if there's a better way to do it, please let me know). Baically I've Club that can have many Courses . now I want to know all the members and instructors of a Club. members and instructors are stored in the Course model, and Club has a reference to them. See the code.. class Course(ndb.Model): ... instructor_keys = ndb.KeyProperty(kind="User", repeated=True) member_keys = ndb.KeyProperty(kind="User", repeated=True) @property def instructors(self): return ndb.get_multi(self.instructor_keys) @property def members(self): return filter(lambda x: x.is_active, ndb

jQuery Autocomplete with Remote JSON Source + Google App Engine + Python

冷暖自知 提交于 2019-12-02 08:49:37
So let's say I have a webapp which just lets users save their hobbies. So I have Kind like this: class Hobby(ndb.Model): hobby_name = ndb.StringProperty() Users just create Hobby entities using this form: <form action="/new-hobby" method="post"> <input type="text" name="hobby_name" id="new-hobby" /> <input type="submit" value="Save New Hobby" /> </form> Then this form is handled by this: # Handles /new-hobby class NewHobby(webapp2.RequestHandler): def post(self): hobby_name = self.request.get('hobby_name') if hobby_name: h = Hobby(hobby_name = hobby) h.put() app = webapp2.WSGIApplication([ ('

Using Key in NDB to retrieve an entity

梦想的初衷 提交于 2019-12-02 08:25:33
问题 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. And I've learn today that if I have all the keys, I can retrieve directly the entity without need of get first the book, then the chapter and then the page, in this way: page_key = ndb.Key('Book', long(bookId), 'Chapter', long(chapterId), 'Page', long(pageId)) page = page_key.get() My doubt is:

Google AppEngine: Form handling 'repeated' StructuredProperty

女生的网名这么多〃 提交于 2019-12-02 08:15:20
How do I work with ndb.StructuredProperty(repeated = True) properties when it comes to designing their forms and handlers? Consider this example: I've got 3 ndb.Model kinds: SkilledPerson , his Education , and his (work) Experience . The latter two are StructuredProperty types of SkilledPerson. class SkilledPerson(ndb.Model): name = ndb.StringProperty() birth = ndb.DateProperty() education = ndb.StructuredProperty(Education, repeated = True) experience = ndb.StructuredProperty(Experience, repeated = True) class Education(ndb.Model): institution = ndb.StringProperty() certification = ndb

Can't execute a distinct projection query

ⅰ亾dé卋堺 提交于 2019-12-02 06:05:14
I have a simple little "Observation" class: from google.appengine.ext import ndb class Observation(ndb.Model): remote_id = ndb.StringProperty() dimension_id = ndb.IntegerProperty() metric = ndb.StringProperty() timestamp_observed = ndb.StringProperty() timestamp_received = ndb.DateTimeProperty(auto_now_add=True) @classmethod def query_book(cls): return cls.query() I can run projection queries against the Datastore to return only certain columns. E.g: observations = Observation.query().fetch(projection=[Observation.dimension_id]) This works nicely, but I only want unique results. The