Suppose we have a base model:
class BaseModel(models.Model):
pass
with some subclasses:
class Submodel1(BaseModel):
some_field = models.TextField()
...
class Submodel9(BaseModel):
another_field = models.TextField()
Each submodel is defined in its own Django app. New apps with new submodels can appear.
We also have another model, let's call it RelatedModel
, which should have a one-to-one relation to BaseModel
:
class RelatedModel(models.Model):
the_thing = models.OneToOneField(BaseModel, null=True, blank=True)
Is it possible to do define such a relation if BaseModel.Meta.abstract == True
?
Or without defining BaseModel
at all?
I have posted some solutions as answers below, but they seem a bit ugly to me.