The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
From: Carl Meyer <carl.j.me...@gmail.com>
Date: Thu, 23 Oct 2008 09:32:13 -0700 (PDT)
Local: Thurs, Oct 23 2008 12:32 pm
Subject: Re: dynamic upcast
Hi harold,
On Oct 23, 9:27 am, dadapapa <dadap...@googlemail.com> wrote:
> If by "save a derived object from a parent instance" you mean that
Sorry, I wasn't clear. You may have a BaseClass instance that is
> the method that saves the object is defined in the parent class, > than this should not cause a problem, since type(self) will > dynamically identify the object as being of the derived type, > so final_type gets initialized correctly. Then again, I might have > misunderstood your problem. "really" a DerivedClass, and if you ever call save() from that BaseClass instance (without casting it to a DerivedClass first), the recipe will break. Code is clearer: >>> d = DerivedClass.objects.create()
<ContentType: derived class>
>>> d.final_type >>> d2 = BaseClass.objects.all()[0]
<ContentType: derived class>
>>> d2.final_type >>> d2.save()
<ContentType: base class>
>>> d2.final_type The fix is just to add an "if not self.id" in the save() method, so
def save(self, *args, **kwargs) :
Carl You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
| ||||||||||||||