Skip to content Skip to sidebar Skip to footer

Workaround To Return A List From A Computedproperty Function In Ndb

I am converting my app to use NDB. I used to have something like this before: @db.ComputedProperty def someComputedProperty(self, indexed=False): if not self.someConditio

Solution 1:

You need to set the repeated=True flag for your computed property in NDB. I don't think you can use the cute "@db.ComputedProperty" notation, you'll have to say:

def_computeValue(self):
    ...same as before...
someComputedProperty = ComputedProperty(_computeValue, repeated=True, indexed=False)

Solution 2:

This whole functionality can be done within a function, so it doesn't need to be a ComputedProperty. Use Computed Properties only when you want to do a computation that you might query for. A ComputedProperty can have its indexed flag set to False but then this means you won't be querying for it, and therefore don't really need to have it as a property.

defsomeComputedProperty(self):
  ifnot self.someCondition:
      return []
  src = self.someReferenceProperty
  list =  src.list1 + src.list2 + src.list3 + src.list4 \
          + [src.str1, src.str2]
  returnmap(lambda x:''ifnot x else x.lower(), list) 

Post a Comment for "Workaround To Return A List From A Computedproperty Function In Ndb"