app-engine-ndb

App Engine NDB query with multiple inequalities?

主宰稳场 提交于 2019-12-04 16:04:34
The only two answers on here involve essentially restructuring the database to accommodate this limitation, but I am unsure how to do that in my case. I have a list of thousands of contacts, each with many many properties. I'm making a page that has an ability to filter on multiple properties at once. For example: Age < 15, Date Added > 15 days ago, Location == Santa Cruz, etc. Potentially a ton of inequality filters required. How does one achieve this in GAE? According to the docs (for python) , Limitations: The Datastore enforces some restrictions on queries. Violating these will cause it to

Following backreferences of unknown kinds in NDB

纵饮孤独 提交于 2019-12-04 11:34:54
问题 I'm in the process of writing my first RESTful web service atop GAE and the Python 2.7 runtime; I've started out using Guido's shiny new ndb API. However, I'm unsure how to solve a particular case without the implicit back-reference feature of the original db API. If the user-agent requests a particular resource and those resources 1 degree removed: host/api/kind/id?depth=2 What's the best way to discover a related collection of entities from the "one" in a one-to-many relationship, given

What's the best way to specify a key_name for App Engine NDB Model?

独自空忆成欢 提交于 2019-12-04 11:17:17
问题 I'm trying to create an ndb model where each record has an unique field "name". I would like to define this field as the key_name field and use it to look up the records. Do I have to include a name field or can I somehow set the key_name field to an arbitrary string that the user can specify as long as it's unique? I'm thinking of using Model.get_or_insert to make sure that old records don't get overwritten, but is there a way to tell if the return value is newly created or pre-existing? I

ndb and consistency: Why is happening this behavior in a query without a parent

萝らか妹 提交于 2019-12-04 10:58:02
I'm doing some work with Python and ndb and can't understand why. I'll post the cases and the code above: models.py class Reference(ndb.Model): kind = ndb.StringProperty(required=True) created_at = ndb.DateTimeProperty(auto_now_add=True) some_id = ndb.StringProperty(indexed=True) data = ndb.JsonProperty(default={}) Those tests are running in the Interactive console and --high_replication option to dev_appserver.py: Test 1 from models import Reference from google.appengine.ext import ndb import random some_id = str(random.randint(1, 100000000000000)) key_id = str(random.randint(1,

How do I know if ndb.Model.get_or_insert created a new entity or got an existing one?

与世无争的帅哥 提交于 2019-12-04 10:35:17
问题 For the following (broken) function, I want to return True if the entity was created or updated, and False otherwise. The problem is that I do not know whether get_or_insert() got an existing entity, or inserted one. Is there an easy way to determine this? class MyModel(ndb.Model): def create_or_update(key, data): """Returns True if entity was created or updated, False otherwise.""" current = MyModel.get_or_insert(key, data=data) if(current.data != data) current.data = data return True return

App engine NDB: how to access verbose_name of a property

纵然是瞬间 提交于 2019-12-04 08:34:15
suppose I have this code: class A(ndb.Model): prop = ndb.StringProperty(verbose_name="Something") m = A() m.prop = "a string value" Now of course if I print m.prop, it will output "a string value" while in fact it's a StringProperty instance. So verbose_name can't be accessed the "normal" way, i.e m.prop._verbose_name . I read the code and found a way to access it: m._properties["prop"]._verbose_name , it works, but it looks hacky o_o. So tell me, is there another way to do it? Note: I'm talking about the NDB API, not the old one Use a class attribute: A.prop._verbose_name . Or m.__class__

Why doesn't appengine auto-convert datetime to UTC when calling put()

你离开我真会死。 提交于 2019-12-04 06:26:47
Here's what I'm trying to do: the user submits a time in pacific, once submitted I use .replace to set the timezone to Pacific. Pacific = time.USTimeZone(-8, "Pacific", "PST", "PDT") addEvent.date = addEvent.date.replace(tzinfo=Pacific) Once i've set the tzinfo, I'm doing a put. According to the python documentation of google appengine it says: "If the datetime value has a tzinfo attribute, it will be converted to the UTC time zone for storage. Values come back from the datastore as UTC, with a tzinfo of None. An application that needs date and time values to be in a particular time zone must

ndb retrieving entity key by ID without parent

£可爱£侵袭症+ 提交于 2019-12-04 04:59:46
I want to get an entity key knowing entity ID and an ancestor. ID is unique within entity group defined by the ancestor. It seems to me that it's not possible using ndb interface. As I understand datastore it may be caused by the fact that this operation requires full index scan to perform. The workaround I used is to create a computed property in the model, which will contain the id part of the key. I'm able now to do an ancestor query and get the key class SomeModel(ndb.Model): ID = ndb.ComputedProperty( lambda self: self.key.id() ) @classmethod def id_to_key(cls, identifier, ancestor):

How to flip to previous page with ndb cursors?

…衆ロ難τιáo~ 提交于 2019-12-04 04:55:55
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_cursor, more = q_forward.fetch_page(app.config['FEEDBACK_PER_PAGE'], start_cursor=cursor) if cursor: rev

How to delete an entity including all children

给你一囗甜甜゛ 提交于 2019-12-04 04:05:50
问题 I would like to do a cascading delete on an entity in the datastore. By this I mean all children and indirect children will also be deleted. I initially assumed this would be default behavior but somehow it is not... My thought was something like this: ndb.delete_multi(ndb.Model.query(ancestor=key).iter(keys_only = True)) But the Model should be a wildcard, because the entity can be the parent of several classes... I would also like to delete BlobKeyProperties when deleting an entity. For