Hi, I would like to know if there is a way to set the key of an entity in google app engine dynamically from a list of unique numbers stored in a csv file and bulkload it to the datastore. Also is it possible to have an entity model with out any properties and just use the the set of predefined unique numbers as keys. Thanks, Arun
views:
52answers:
1Yes, I think that is completely possible.
Only keep in mind that a key has to be unique across the whole application, so if you use it as the key for an entity in the data model you design to keep the keys, you won't be able to use it in your application's real data models entities (wherever you intend to use the key in the end).
I presume you want to create an entity per entry in the csv file and that's why you ask about the empty data model, all you want is to store the key until it gets assigned. For the reason I gave you above I think you should have another Property, probably a StringProperty, to hold the key.
Just make sure that when you do the key assignment by doing something like
class PrecalculatedKey(db.Model):
precalc_key = db.StringProperty(required=True)
precalculated_key = PrecalculatedKey.all().fetch(1)
s = AppModel(key_name=precalculated_key.precalc_key)`
the whole thing (fetching a new key, using it on an AppModel and deleting the used key from the model) happens inside a transaction, you don't want to give the same key to two different AppModel entities.