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>You could generate your own key in class Category based on the 'name' field and use it: </p>

<p>1) when you generate a new Category entity</p>

<p>2) when you need to query Product against a specific category. </p>

<p>So after Category entities have a key you can generate at any time, you could say: </p>

<p>category_key = Category.create_key(name='CertainName')</p>

<p>query = Product.query(Product.category == category_key)</p>

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