app-engine-ndb

Query random row in ndb [closed]

只愿长相守 提交于 2019-12-29 09:10:27
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 6 years ago . I am trying to develop an web app on google app engine using webapp2. One of the thing I need to do is to retrieve a random from ndb and display it. Is it any effective method that allows me to do so? 回答1: I assume you mean a random record when you say "random from ndb". If you

Backward pagination with cursor is working but missing an item

筅森魡賤 提交于 2019-12-29 06:54:25
问题 From looking for ideas/alternatives to providing a page/item count/navigation of items matching a GAE datastore query, I could find a hint how to backward page navigation with a single cursor by REVERSING ORDER. class CursorTests(test_utils.NDBTest): def testFirst(self): class Bar(model.Model): value = model.IntegerProperty() self.entities = [] for i in range(10): e = Bar(value=i) e.put() self.entities.append(e) q = Bar.query() bars, next_cursor, more = q.order(Bar.key).fetch_page(3) barz,

Backward pagination with cursor is working but missing an item

放肆的年华 提交于 2019-12-29 06:54:06
问题 From looking for ideas/alternatives to providing a page/item count/navigation of items matching a GAE datastore query, I could find a hint how to backward page navigation with a single cursor by REVERSING ORDER. class CursorTests(test_utils.NDBTest): def testFirst(self): class Bar(model.Model): value = model.IntegerProperty() self.entities = [] for i in range(10): e = Bar(value=i) e.put() self.entities.append(e) q = Bar.query() bars, next_cursor, more = q.order(Bar.key).fetch_page(3) barz,

Memory leak in Google ndb library

痴心易碎 提交于 2019-12-28 04:04:29
问题 I think there is a memory leak in the ndb library but I can not find where. Is there a way to avoid the problem described below? Do you have a more accurate idea of testing to figure out where the problem is? That's how I reproduced the problem : I created a minimalist Google App Engine application with 2 files. app.yaml : application: myapplicationid version: demo runtime: python27 api_version: 1 threadsafe: yes handlers: - url: /.* script: main.APP libraries: - name: webapp2 version: latest

how to subclass google app engine ndb property to support python subclassed objects

风格不统一 提交于 2019-12-25 07:35:32
问题 from this article https://stackoverflow.com/a/32107024/5258689 I have a dict() subclass - that allows me to do dict.key (use dot to access keys i mean) - as follows: class Permissions(dict): """ Example: m = Map({'first_name': 'Eduardo'}, last_name='Pool', age=24, sports=['Soccer']) """ def __init__(self, *args, **kwargs): super(Permissions, self).__init__(*args, **kwargs) for arg in args: if isinstance(arg, dict): for k, v in arg.iteritems(): self[k] = v if kwargs: for k, v in kwargs

Expected BlobKey but instead I get a BlobInfo object - How to get BlobKey from BlobInfo object?

余生颓废 提交于 2019-12-25 07:30:06
问题 What's the best way to get a BlobKey from a BlobInfo object? def get(self): blobs = BlobInfo.all() #something is missing here for blob in blobs: if not Content.query().filter(ndb.BlobKeyProperty("blobKey") == blob.key).count(1): #ERROR blob.delete() ^ **how do you do make this a normal BlobKey?** #Error BadValueError: Expected BlobKey, got <bound method BlobInfo.key of <google.appengine.ext.blobstore.blobstore.BlobInfo object at 0x048B87D0>> Thanks!! 回答1: BlobInfo.key is a method, not a

How do I get the value of a StringProperty in Python for Google App Engine?

喜你入骨 提交于 2019-12-25 04:43:11
问题 How do I get the values of a nbd.Model? I want to return a description that is composed of several of the fields but I can't get it to work. This is my code for my class: class User(ndb.Model): name = ndb.StringProperty() email = ndb.StringProperty() @classmethod def get_description(self): # return "Kobe Bryant (kobe.bryant@lakers.net)" return self.name + ' (' + self.email + ')' But name is a StringProperty object and can't be appended to a string. How do I get the value of the StringProperty

How do I get the value of a StringProperty in Python for Google App Engine?

怎甘沉沦 提交于 2019-12-25 04:43:02
问题 How do I get the values of a nbd.Model? I want to return a description that is composed of several of the fields but I can't get it to work. This is my code for my class: class User(ndb.Model): name = ndb.StringProperty() email = ndb.StringProperty() @classmethod def get_description(self): # return "Kobe Bryant (kobe.bryant@lakers.net)" return self.name + ' (' + self.email + ')' But name is a StringProperty object and can't be appended to a string. How do I get the value of the StringProperty

difference between DateProperty and DateTimeProperty

醉酒当歌 提交于 2019-12-25 03:47:13
问题 In layman's term, what's the difference between ndb.DateProperty and ndb.DateTimeProperty ? When would I use which? For example, my intent is to use either with the param auto_now_add=True . 回答1: From the docs: These take values belonging to the corresponding classes (date, time, datetime) of the standard Python datetime module. The most general of the three is DateTimeProperty, which denotes both a calendar date and a time of day; the others are occasionally useful for special purposes

google app engine NDB records counts from NDB model

折月煮酒 提交于 2019-12-25 03:35:26
问题 How many records we can get from google app engine from single query so that we can display count to user and is we can increase timeout limit 3 seconds to 5 seconds 回答1: In my experience, ndb cannot pull more than 1000 records at a time. Here is an example of what happens if I try to use .count() on a table that contains ~500,000 records. s~project-id> models.Transaction.query().count() WARNING:root:suspended generator _count_async(query.py:1330) raised AssertionError() Traceback (most