Deleting a model object that has related objects will only cascade delete those objects if their models have been imported.
Is this true? I have not found it in the documentation and would like to add a reference to the code comment so others won't be as confused as I am.
mymodel.py:
from django.db import models
class MyModel(models.Model):
foo = models.CharField()
bar = models.CharField()
my_other_model.py:
from django.db import models
from mymodel import MyModel
class MyOtherModel(models.Model):
baz = models.CharField()
bar = models.ForeignKey(MyModel)
some_source_file.py:
from mymodel import MyModel
# Without this line, deleting MyModel objects will not delete its related
# MyOtherModel objects (?):
from my_other_model import MyOtherModel
obj = MyModel.objects.get(pk=123)
obj.delete()