How to retrieve entities from Google Cloud Datastore
<p>I have some problems with Cloud Datastore in Google App Engine.</p>

<p>I have 2 Models in the database which are:</p>

<pre><code>class Product(ndb.Model):
    name = StringProperty(required=True)
    category = KeyProperty(kind=Category)
    description = TextProperty(required=True)
    price = IntegerProperty(required=True)
</code></pre>

<p>And</p>

<pre><code>class Category(ndb.Model):
    name=StringProperty(required=True)
</code></pre>

<p>So how can i get all the datas from Product Class that belong to a certain Category?</p>

<p>In Relational SQL i used:</p>

<pre><code>SELECT * FROM Product WHERE category = 'CertainName';
</code></pre>

<p>Thank you!</p>

<p>The following should perform what your sql query is doing:</p>

<pre><code>query = Product.query(Product.category == "CertainName") # Note the "=="
</code></pre>

<p>Edit:</p>

<p>I just realized you need to filter by key(thank you @mgilson). The query changes a little. Basically you just need to first get your category_entity and then apply the filter like this:</p>

<pre><code>query = Product.query(Product.category == category_entity.key)
</code></pre>

<p>where, for example, you could fetch a category_entity like shown below:</p>

<pre><code>category_entity = Category.query(Category.name == "SomeCat").fetch()
</code></pre>

<p>Refer to <a href="https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/appengine/standard/ndb/queries/snippets.py" rel="nofollow">https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/appengine/standard/ndb/queries/snippets.py</a> for more info (look at query_purchases_for_customer_via_key)</p>

python google-app-engine nosql google-cloud-datastore