Re: dynamic upcast

2008-10-23 Thread Carl Meyer
Hi harold, On Oct 23, 9:27 am, dadapapa <[EMAIL PROTECTED]> wrote: > If by "save a derived object from a parent instance" you mean that > 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 objec

Re: dynamic upcast

2008-10-23 Thread dadapapa
On Oct 19, 10:10 pm, Carl Meyer <[EMAIL PROTECTED]> wrote: > Just ran into this issue myself (first time using non-abstract > inheritance).  The catch with this recipe is that you can never save a > derived object from a parent instance, or you break the final_type > field (it will then contain th

Re: dynamic upcast

2008-10-19 Thread Carl Meyer
On Sep 12, 2:57 pm, dadapapa <[EMAIL PROTECTED]> wrote: >     class BaseClass(models.Model) : >         final_type = models.ForeignKey(ContentType) > >         def save(self,*args) : >             self.final_type = > ContentType.objects.get_for_model(type(self)) >             super(BaseClass,sel

Re: dynamic upcast

2008-09-16 Thread dadapapa
Hi Malcolm, Malcolm Tredinnick wrote: > > class BaseClass(models.Model) : > > final_type = models.ForeignKey(ContentType) > > > > def save(self,*args) : > > For absolute robustness, you should also accept **kwargs here. There are > a couple of places in Django's code that will

Re: dynamic upcast

2008-09-16 Thread Malcolm Tredinnick
On Fri, 2008-09-12 at 11:57 -0700, dadapapa wrote: > > It does not work at all. For some reason, final_type also gets > > upcasted to MediaObject?! > > I found the solution, now. The problem was that the __init__ method of > a Model is also called when objects are restored from the database. So

Re: dynamic upcast

2008-09-12 Thread dadapapa
> It does not work at all. For some reason, final_type also gets > upcasted to MediaObject?! I found the solution, now. The problem was that the __init__ method of a Model is also called when objects are restored from the database. So when the base class gets initialized by the QueryManager, it o