NDB Query for Key or ID of StructuredProperty

497 views Asked by At

I'm new in Python and Google App Engine and have problems to fetch specific data from Datastore by using NDB.

I want to count the results of a query, where a StructuredProperty has the given key/entity/id:

class MyData(ndb.Model):
    group = ndb.StructuredProperty(MyGroup)

    @classmethod
    def get_count_by_group(cls, entity):
        return cls.query(MyData.group.key == entity.key).count()
        #return cls.query(MyData.group == entity).count()

The given entity is the instance of a Model, so I can access key and the id. After the call it fails, because property key is not found for "MyGroup". The documentation of NDB Queries contains examples for using filter on class properties and it works in other functions but I don't know how to query/filter for "internal" properties of the Model like key or id.

0

There are 0 answers