app-engine-ndb

how to display parent entity while looping through child entities in Jinja2 template

折月煮酒 提交于 2019-12-12 02:12:25
问题 How to use this solution https://stackoverflow.com/a/10067749/604240 in jinja 2 template? 回答1: I agree my question was due to lack of knowledge than problem. Eventually I figured it out how to achieve it. Basically I didn't know how to link loop from python code to query so it's available to Jinja2 template. Although correct solution might be to use map() with callback function https://developers.google.com/appengine/docs/python/ndb/queryclass#Query_map but I am using temporary solution which

ndb many to many, retrieve list of one of the relation

为君一笑 提交于 2019-12-12 01:56:01
问题 I've this table class ClubMembership(GCModel): member = ndb.KeyProperty(kind='User', required=True) club = ndb.KeyProperty(kind='Club', required=True) is_active = ndb.BooleanProperty(default=True) membership_type = ndb.StringProperty(choices=set(["MEMBER", "TRAINER", "OWNER"]), default="MEMBER", required=True) Then in the Table Club i've this class Club(GCModel): @property def members(self): return ClubMembership.query(ndb.AND(ClubMembership.club == self.key, ClubMembership.membership_type ==

AppEngine NDB PolyModel getting properties

不羁的心 提交于 2019-12-12 01:34:49
问题 I am having a problem with appengine that I can't seem to figure out: from google.appengine.ext import ndb from google.appengine.ext.ndb import polymodel class Item(polymodel.PolyModel): name = ndb.StringProperty() type = ndb.StringProperty(choices=["Medical","Food"]) sub_category_type = ndb.StringProperty() sub_category_sub_type = ndb.StringProperty() class MedicalItem(Item): med_sub_type = ndb.StringProperty() can_split_item = ndb.BooleanProperty() class ItemInHouse(ndb.Model): item = ndb

Google App Engine: Modifying 1000 entities using TaskQueue

岁酱吖の 提交于 2019-12-11 23:38:27
问题 I am hoping to modify 1000 entities using task queue, as suggested Zig Mandel in my original question here: Google App Engine: Modifying 1000 entities I have a UserAccount kind like this: class UserAccount(ndb.Model): email = ndb.StringProperty() Some of the UserAccount email s contain uppercases (example: JohnathanDough@email.com), and I would like to apply email.lower() to every entity's email. So I've set up a task queue like this: class LowerEmailQueue(BaseHandler): def get(self): all

Parse value to None in ndb custom property

最后都变了- 提交于 2019-12-11 19:29:25
问题 I have a custom ndb property subclass which should parse an empty string to None. When I return None in the _validate function, the None value is ignored and the empty string is still used. Can I somehow cast input values to None? class BooleanProperty(ndb.BooleanProperty): def _validate(self, value): v = unicode(value).lower() # '' should be casted to None somehow. if v == '': return None if v in ['1', 't', 'true', 'y', 'yes']: return True if v in ['0', 'f', 'false', 'n', 'no']: return False

NDB HRD transactions, which ancestor determines the entity group?

℡╲_俬逩灬. 提交于 2019-12-11 19:17:16
问题 Is it the closest or the most distant parent relative of the entity being written, which determines the entity group? ( Question 1 ) For, if I have, two simultaneous requests to write two different entities, in this example, both having immediate parent the Data entity (with key '2'), and having subsequent ancestors of: Person:9 > Collection:3 > Script:4 > Data:2 > Record of Tom Cruise Person:9 > Collection:3 > Script:4 > Data:2 > Record of Shia La Boef In either case they both belong to the

Assigning an author to an entity during its creation

烈酒焚心 提交于 2019-12-11 13:34:38
问题 I am doing Udacity's Web Dev Course with Google Appengine and Python. I would like to know how I could assign to a created entity, its own author . For example, I have two ndb.Models kinds: class User(ndb.Model): username = ndb.StringProperty(required = True) bio = ndb.TextProperty(required = True) password = ndb.StringProperty(required = True) email = ndb.StringProperty() created = ndb.DateTimeProperty(auto_now_add = True) class Blog(ndb.Model): title = ndb.StringProperty(required = True)

Wait for datastore update before proceeding

百般思念 提交于 2019-12-11 10:37:36
问题 I'm working on a lightweight app, and I have quite a few situations where the user submits a form, the form data is processed and pushed to the datastore, and then the user is redirected to a page that displays some of the same data. It's quite often the case that the user gets to the page before the datastore has been updated, so they see old data. Is there any way to have the app wait for the datastore to update before proceeding? The obvious hacky solution is calling sleep(1) , but that's

GAE Endpoints error: Expected FooBar Instance, got FooBar()

て烟熏妆下的殇ゞ 提交于 2019-12-11 10:05:59
问题 I'm managing an API with using Google Cloud Endpoints and am struggling with a strange, randomly happening, error. The error happens in production only, the unit tests pass property. I have the following model: class UserFacebookData(ndb.Model): facebook_id = ndb.StringProperty(required=True, indexed=True) facebook_token = ndb.StringProperty(required=True, indexed=True) class User(ndb.Model, Entity): created = ndb.DateTimeProperty(auto_now_add=True, indexed=True) username = ndb.StringProperty

How to find out if a model class is db or a ndb

三世轮回 提交于 2019-12-11 09:54:27
问题 I created a utility to exchange or zip all the entities for a kind. But how can I find out if the model_class used is a db.Model or an ndb.Model? def _encode_entity(self, entity): if self.ndb : entity_dict = entity.to_dict() self.entity_eid = entity.key.id() entity_dict['NDB'] = True else : entity_dict = db.to_dict(entity) self.entity_eid = entity.key().name() entity_dict['NDB'] = False .... Now I use : def queryKind(self): try : self.query = self.model_class.query() self.ndb = True except