In the Google App Engine, what's the difference between Model.get (key) and Model.get_by_key_name (key_names)?

Is a key (key) required for an entity key, and get_by_key_name (key_names) requires a key name?

+7
google-app-engine google-cloud-datastore
source share
2 answers

There is a difference. An object in a data warehouse is identified by a combination of its Kind, its parent, and its identifier. ( link ). The identifier can be either a number or a string. The Key object contains both identifier and parent information. Therefore, when you call get (), there is only one argument - the Key object. When you call get_by_key_name, note that there are two arguments: one is key_name, one is parent.

So, the key is an object with several parts, while the key name is just a string. To make things more confusing, the Key object can be encoded as a string.

+10
source share

Here is the official explanation of get () , and this is for get_by_key_name () I hope this helps.

0
source share

All Articles