Skip to content

Instantly share code, notes, and snippets.

@nealtodd
nealtodd / deletable_objects_snippet.py
Last active August 10, 2020 06:49
Django helper for showing related objects that would be cascade deleted on deletion of an object.
from django.conf import settings
from django.db.models.deletion import Collector
from django.db.utils import ConnectionRouter
def deletable_objects(obj):
"""
Return a generator that yields (model, instance) tuples
of instances related to obj (including obj itself).
Essentially, programmatic access to the data Django Admin