Hi Jeff,
On Sat, Aug 22, 2009 at 7:24 PM, Jeff Enderwick <[email protected]>wrote:
>
> Currently, one must put() in order to have obj.key() be valid. In some
> flows, I find my self having to put() object twice for this reason.
>
> If I make a synthetic key, it appears that I can avoid this:
>
> class Joker(db.Model):
> unused = db.StringProperty()
> def __init__(self):
> m = hashlib.sha1()
> m.update(str(time.time()))
> name = base64.b64encode(m.digest())
> logging.debug("name="+name)
> db.Model.__init__(self, key_name=name)
>
> 1) GOOG folks - are there any performance downsides to taking this
> approach?
Not really, no.
>
> 2) If no, are there any other environmental factors that might be
> fodder for the hash (user, etc)?
I would recommend using uuid.uuid4().hex instead of a straight SHA1 sum.
UUIDs are guaranteed to be unique.
I would also recommend defining a class method called something like
'create' that generates the key name and calls __init__. There are
subtle-use cases around __init__ and reconstructing entities from the
datastore, and it's difficult to get right - much more straightforward to
define a class method to construct new entities.
-Nick Johnson
>
> Thanks,
> Jeff
>
> >
>
--
Nick Johnson, Developer Programs Engineer, App Engine
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Google App Engine" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/google-appengine?hl=en
-~----------~----~----~----~------~----~------~--~---