Reputation: 50362
In the low-level Java api, I used to be able to make up entity names at runtime.
In python, it seems that I have to pre-define a class name that is also my entity name:
class SomeKindaData(db.Expando):
pass
sKD = SomeKindaData(key_name='1')
...
Is there a way to make entity names up at run time in App Engine for Python?
Upvotes: 1
Views: 229
Reputation: 12838
Entities themselves don't have names. In the datastore, entities are identified by keys, which can have names or IDs. You're setting your entity's key name to "1" in your sample code. Entities are also classified by kind, in this case SomeKindaData.
db.Model and db.Expando provide a local ORM abstraction around the datastore. When you use these, your entity's kind name is set to your model class name by default. If you don't want to define a model class before creating an entity, you can use the low-level datastore API:
from google.appengine.api import datastore
sKD = datastore.Entity(kind='SomeKindaData', name='1')
sKD['SomeProperty'] = 'SomeValue'
datastore.Put(sKD)
Upvotes: 2