Hi Patrick,

It's never 'safe' to mess with the internals of Python like this. As a rule,
if you're trying to change the class of an existing object, that's a code
smell, and you should almost certainly be implementing it differently, such
as by using a single class and changing a status variable.

-Nick Johnson

On Wed, Sep 28, 2011 at 12:42 AM, PatrickCD <patrick.do...@gmail.com> wrote:

> Hello,
>
> Is it safe to change the __class__ attribute of a PolyModel instance
> and then save it back to the datastore?
>
> e.g.
>
> class DraftProject(PolyModel):
>    def someaction(self):
>         print 'Action permitted at this status'
>
> class ApprovedProject(DraftProject):
>    def someaction(self):
>         raise Exception('not allowed at this status')
>
> p = DraftProject.get(object_key)
> p.__class__ = ApprovedProject
> p.put()
>
>
> I've a got a model class that corresponds to a project in a workflow
> application. The project can be at different statuses. Depending on
> the status, some actions are permissible, and some are not. I'd like
> to use the Template design pattern to model this (http://
> en.wikipedia.org/wiki/Template_method_pattern)
>
> If setting the class attribute directly is unsafe, could anyone
> suggest a better way to model this?
>
> Thanks
>
> --
> 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.
>
>


-- 
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 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.

Reply via email to