Search code examples
pythondjangogoogle-app-enginegoogle-cloud-datastoredjango-nonrel

The App Engine datastore can either return entire entities or only entity keys from a query?


I am reading Google App Engine doc and found this line difficult to understand

The App Engine datastore can either return entire entities or only entity keys from a query.

what does it mean? There is filter(property_operator, value) and fetch(limit, offset=0)

And I believe django-nonrel support values() on App Engine. So what does it mean?


Solution

  • You can do a standard query, like this:

    results = MyModel.all().filter('foo =', 'bar').fetch(20)
    

    That will return a list of entities (db.Model instances). Or, you can do a keys-only query, like this:

    results = MyModel.all(keys_only=True).filter('foo =', 'bar').fetch(20)
    

    That will return only the keys of the matching entities (db.Key instances), and is faster to execute than the first query.