On Oct 23, 9:27 am, dadapapa <dadap...@googlemail.com> wrote:
> If by "save a derived object from a parent instance" you mean thatSorry, 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>
>>> d2 = BaseClass.objects.all()<ContentType: derived class>
>>> d2.save()<ContentType: base class>
The fix is just to add an "if not self.id" in the save() method, so
def save(self, *args, **kwargs) :
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.