I have these two models:
class Interface(models.Model):
# fields
class OldInterface(models.Model):
interface = models.ForeignKey(_base,related_name='old_versions')
class Meta:
abstract = True
Inherited by their “Spatial” and “Functional” variants :
class SpatialInterface(Interface):
# fields
class OldSpatialInterface(OldInterface):
_base = SpatialInterface
class FunctionalInterface(Interface):
# fields
class OldFunctionalInterface(OldInterface):
_base = FunctionalInterface
Of course my code fails, because _base is not defined in the parent Model.
My question is : Is there any way, or trick to tell the ForeignKey to read to the target model from the child Model ?
Or more generally, is there any way, to, in the parent class, dynamically read a variable located in the child class ?
From my researches, I think that this is not possible, because of the way syncdb parses the models.py :
__init__()is not called and so I didn’t find any way to dynamically set the ForeignKey target based on the child.