David_Hogan
David_Hogan

Reputation: 125

Get Key Name Length Google App Engine NDB

I'm currently trying to use ComputedProperties to obtain the length of the my key name which is a collection of letters from example xyz using the below code.

ndb.ComputedProperty(lambda e: len(e.get_by_id))

The issue I'm having is I cant seem to find a way of access the key within the model to get its length and then define this as a Computer Property.

I thought of storing the key as a string within the model but that duplicates things for no good reason.

Upvotes: 0

Views: 41

Answers (1)

GAEfan
GAEfan

Reputation: 11360

How about an @property?:

@property
def key_length(self):
   return len( self.key.string_id() )

or lambda:

ndb.ComputedProperty( lambda self: len( self.key.string_id() ) )

This solves the question

Upvotes: 1

Related Questions