Tim, Thanks for that informative and useful answer. I was a apprehensive messing with the datastore class machinery. The approach I adopted was (directly setting __class__ attribute) appears to work. However, as you suggest, it seems likely this behaviour is not something to rely on. I agree that using some sort or adapter / factory method is probably better. Thanks again.
Regards Patrick On Sep 28, 12:35 am, Tim Hoffman <zutes...@gmail.com> wrote: > Hi > > You wouldn't do it that way, and it won'tt work (well it might if you really > want to go way under the hood) > > The "class" property of the PolyModel stores an ordered list of parent > classes. The base class that will be looked up on retrieval from the > datastore is defined in the Key, and in your case will always be > "DraftProject". When the entity is retrieved from the Datastore the > Key's path is used to resolve the base class. Then metaclasses kick in and > it actually returns an instance of the subclass > You can't change the key of an entity. > > Have a look at polymodel based entities in the datastore. You will see that > the "class" property stores a list of Class names. > > However I have yet to work out a way to change the class, manipulating the > "class" property doesn't work ;-) > If you go under the hood and change the "class" property in a raw entity it > would work though. But this is getting seriously messy. > > I would seriously reconsider if this is a path you want to take. Why not > consider using adapters and have a simple class > that stores the entities properties (workflow) status and then wrap the > entity with an adapter with the methods you want etc... based on the status. > > I feel this would be a better approach. I use adapters (zope.component) on > appengine in pretty much all of my projects. It would > give you the same behaviour r without having to hack around with the > PolyModel metaclass machinery. > > Regards > > Tim Hoffman -- You received this message because you are subscribed to the Google Groups "Google App Engine" group. To post to this group, send email to google-appengine@googlegroups.com. To unsubscribe from this group, send email to google-appengine+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/google-appengine?hl=en.