I have a custom delete method on my Model that I make sure is called correctly when calling delete on the QuerySet by using:
Custom delete method on queryset.
This does not seem to work when Django performs a cascading delete. In that case, the ORM calls _raw_delete on a regular QuerySet thereby bypassing my custom delete method.
How do I prevent that from happening?
The issue seems to be caused because this uses _base_manager rather than _default_manager:
def related_objects(self, related, objs):
return related.related_model._base_manager.using(self.using).filter(
**{"%s__in" % related.field.name: objs}
)