Skip to content

Instantly share code, notes, and snippets.

@ewjoachim
Created September 2, 2015 13:38
Show Gist options
  • Save ewjoachim/d2bf713a26911161ab7a to your computer and use it in GitHub Desktop.
Save ewjoachim/d2bf713a26911161ab7a to your computer and use it in GitHub Desktop.
def get_linked_objects(obj):
"""
Returns all the objects that would be deleted if a cascade deletion were to be done.
"""
links = [rel.get_accessor_name() for rel in obj._meta.get_all_related_objects()]
return [liked_obj for link in links for liked_obj in getattr(obj, link).all()]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment