For absolute robustness, you should also accept **kwargs here. There are
a couple of places in Django's code that will call save() and pass in
force_insert=True, for example, which won't be handled by *args. In
reality, all you need to be able to handle is force_insert and
force_update, but *args and **kwargs are also pretty useful,
particularly if you aren't doing anything with them except passing them
along.
> self.final_type =
> ContentType.objects.get_for_model(type(self))
> super(BaseClass,self)save(*args)
>
> def cast(self) :
> return
> self.final_type.get_object_for_this_type(id=self.id)
>
> class DerivedClass(ParentClass) :
> pass
>
> Here is an example:
>
> obj = DerivedClass()
> obj.save()
>
> obj = get_object_or_404(BaseClass, id=3).cast()
> # obj is now of type DerivedClass
Yes, well done. This looks like the right way to handle this. Glad
somebody's documented it here.
Regards,
Malcolm