Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I'm not sure what kinds of queries you'll need to do in addition to those mentioned in the question, but storing the data in an explicit ancestor hierarchy would make the ones you asked about fall out pretty easily.</p> <p>For example, to get all wines from a particular origin:</p> <pre><code>origin_key = db.Key.from_path('Origin', 123) wines_query = db.Query(Wine).ancestor(origin_key) </code></pre> <p>or to get all wines from a particular winery:</p> <pre><code>origin_key = db.Key.from_path('Origin', 123) winery_key = db.Key.from_path('Winery', 456, parent=origin_key) wines_query = db.Query(Wine).ancestor(winery_key) </code></pre> <p>and, assuming you're storing the variety as a property on the Wine model, all wines of a particular variety is as simple as</p> <pre><code>wines_query = Wine.all().filter('variety =', 'merlot') </code></pre> <p>One possible downside of this strict hierarchical approach is the kind of URL scheme it can impose on you. With a hierarchy that looks like</p> <pre><code>Origin -&gt; Winery -&gt; Wine </code></pre> <p>you must know the key name or ID of a wine's origin <em>and</em> winery in order to build a key to retrieve that wine. Unless you've already got the string representation of a wine's key. This basically forces you to have URLs for wines in one of the following forms:</p> <ul> <li><code>/origin/{id}/winery/{id}/wine/{id}</code></li> <li><code>/wine/{opaque and unfriendly datastore key as a string}</code></li> </ul> <p>(The first URL could of course be replaced with querystring parameters; the important part is that you need three different pieces of information to identify a given wine.)</p> <p>Maybe there are other alternatives to these URL schemes that have not occurred to me, though.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload