I’m trying to use a multi-table inheritance model as a through table, as shown below:
class Base(models.Model):
...
class Through(Base):
...
class RelatedModel(models.Model):
...
class Model(models.Model):
field = models.ManyToManyField(RelatedModel, through='Base')
instance = Model.objects.get(pk=1)
related = RelatedModel.objects.get(pk=1)
instance.add(related) # ValueError: Can't bulk create a multi-table inherited model
However, I keep running into an error when adding a model to the ManyToMany relationship, as to how multi-table inheritance models cannot be bulk created. Is there any way around this? ManyToManyField.add doesn’t take a bulk
argument so it doesn’t seem to be possible to disable bulk creation there.
Does anyone know of a workaround for this without getting rid of the inheritance?